microsoft / vscode-dev-containers

NOTE: Most of the contents of this repository have been migrated to the new devcontainers GitHub org (https://github.com/devcontainers). See https://github.com/devcontainers/template-starter and https://github.com/devcontainers/feature-starter for information on creating your own!
https://aka.ms/vscode-remote
MIT License
4.7k stars 1.41k forks source link

Docker container is not persistent when launched with compose configuration #1760

Open TheDreamsWind opened 11 months ago

TheDreamsWind commented 11 months ago

I have a CMake project which I need to debug and compile for various platforms. For this specific example I use a minimalistic EulerOS image (it's almost empty, with nearly zero applications installed out of the box). This image comes from my company in-house registry, so in order to use it I manually create the following .devcontainer/devcontainer.json configuration which refers to my custom image:

{
  "image": "my_euler_image",
  "customizations": {
    "vscode": {
      "extensions": ["streetsidesoftware.code-spell-checker"]
    }
  },
}

Then, if I open the workspace from within WSL, and run Dev Containers: Reopen in Container it works just fine, i.e. VSCode automagically creates the container out of the image, mounts the workspace and keeps it running for me. However for my case I also need Kafka infrastructure, so I made a docker-compose.yaml configuration:

version: "3"
services:
  zookeeper:
    ...
  kafka:
    ...
  euleros:
    tty: true
    build: "path/to/Dockerfile"
    depends_on:
      - kafka
network:
  default:
    name: my_network

And changed the devcontainer.json correspondingly:

{
  "dockerComposeFile": "path/to/docker-compose.yml"
  "service": "euleros"
  "runServices": [ "euleros" ],
  "mounts":[
    { "source": "../relative/path/to/workspace", "target": "/mnt/path/to/workspace", "type": "volume" }
  ],
  "workspceFolder": "/mnt/path/to/workspace",
  "customizations": {
    "vscode": {
      "extensions": ["streetsidesoftware.code-spell-checker"]
    }
  }
}

In this case, however, if I run Dev Containers: Reopen in Container, for some reason I have to mount the target service directory manually (by providing this information in the devcontainer.json file above). More importantly - VSCode doesn't maintain the persistence of the target service anymore in this case and get disconnected by timeout of tty mode.

Isn't VSCode supposed to keep it running and mount my workspace itself just like it does for single-image scenario? And if not, how do I handle it properly?