Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't switch between containers using docker-compose.yaml #9435

Closed
raulbocanegra opened this issue Jan 25, 2024 · 7 comments
Closed

Can't switch between containers using docker-compose.yaml #9435

raulbocanegra opened this issue Jan 25, 2024 · 7 comments
Assignees
Labels
containers Issue in vscode-remote containers feature-request Request for new features or functionality

Comments

@raulbocanegra
Copy link

raulbocanegra commented Jan 25, 2024

I have a repo with 2 devcontainers using docker-compose.yaml.
The structure is something like:

.devcontainer
├── docker-compose.yaml
├── python2
│   ├── devcontainer.json
│   ├── Dockerfile
│   └── post-create-command.sh
└── python3
    ├── devcontainer.json
    ├── Dockerfile
    └── post-create-command.sh
  • VSCode Version:
    Version: 1.85.1
    Commit: 0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2
    Date: 2023-12-13T09:47:11.635Z
    Electron: 25.9.7
    ElectronBuildId: 25551756
    Chromium: 114.0.5735.289
    Node.js: 18.15.0
    V8: 11.4.183.29-electron.0

  • Local OS Version: Linux x64 amd64

  • Remote Extension/Connection Type: Containers

  • Logs:

[2024-01-25T00:45:00.398Z] Dev Containers 0.327.0 in VS Code 1.85.1 (0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2).
[2024-01-25T00:45:00.398Z] Start: Resolving Remote
[2024-01-25T00:45:00.403Z] Setting up container for folder or workspace: /home/user/code/vt-core
[2024-01-25T00:45:00.405Z] Start: Check Docker is running
[2024-01-25T00:45:00.405Z] Start: Run: docker version --format {{.Server.APIVersion}}
[2024-01-25T00:45:00.428Z] Stop (23 ms): Run: docker version --format {{.Server.APIVersion}}
[2024-01-25T00:45:00.428Z] Server API version: 1.41
[2024-01-25T00:45:00.428Z] Stop (23 ms): Check Docker is running
[2024-01-25T00:45:00.428Z] Start: Run: docker volume ls -q
[2024-01-25T00:45:00.444Z] Stop (16 ms): Run: docker volume ls -q
[2024-01-25T00:45:00.444Z] Start: Run: docker ps -q -a --filter label=vsch.local.folder=/home/user/code/vt-core --filter label=vsch.quality=stable
[2024-01-25T00:45:00.458Z] Stop (14 ms): Run: docker ps -q -a --filter label=vsch.local.folder=/home/user/code/vt-core --filter label=vsch.quality=stable
[2024-01-25T00:45:00.459Z] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/home/user/code/vt-core --filter label=devcontainer.config_file=/home/user/code/vt-core/.devcontainer/python2/devcontainer.json
[2024-01-25T00:45:00.474Z] Stop (15 ms): Run: docker ps -q -a --filter label=devcontainer.local_folder=/home/user/code/vt-core --filter label=devcontainer.config_file=/home/user/code/vt-core/.devcontainer/python2/devcontainer.json
[2024-01-25T00:45:00.474Z] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/home/user/code/vt-core
[2024-01-25T00:45:00.491Z] Stop (17 ms): Run: docker ps -q -a --filter label=devcontainer.local_folder=/home/user/code/vt-core
[2024-01-25T00:45:00.492Z] Start: Run: docker inspect --type container ed51471bc250
[2024-01-25T00:45:00.509Z] Stop (17 ms): Run: docker inspect --type container ed51471bc250
[2024-01-25T00:45:00.509Z] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/home/user/code/vt-core
[2024-01-25T00:45:00.526Z] Stop (17 ms): Run: docker ps -q -a --filter label=devcontainer.local_folder=/home/user/code/vt-core
[2024-01-25T00:45:00.526Z] Start: Run: docker inspect --type container ed51471bc250
[2024-01-25T00:45:00.541Z] Stop (15 ms): Run: docker inspect --type container ed51471bc250
[2024-01-25T00:45:00.542Z] Start: Run: docker exec -i -u root ed51471bc250fbf241feccb7a508b3267966e7eddfac8a6c1880d45875f7c9bf /bin/sh -c echo "Container already running. Keep-alive process started." ; export VSCODE_REMOTE_CONTAINERS_SESSION=94dca675-75a1-43b1-ac52-55612a5dff611706143500039 ; /bin/sh
[2024-01-25T00:45:00.545Z] Start: Run: /usr/share/code/code --ms-enable-electron-run-as-node /home/user/.vscode/extensions/ms-vscode-remote.remote-containers-0.327.0/dist/spec-node/devContainersSpecCLI.js read-configuration --workspace-folder /home/user/code/vt-core --id-label devcontainer.local_folder=/home/user/code/vt-core --id-label devcontainer.config_file=/home/user/code/vt-core/.devcontainer/python2/devcontainer.json --log-level debug --log-format json --config /home/user/code/vt-core/.devcontainer/python2/devcontainer.json --mount-workspace-git-root
[2024-01-25T00:45:00.624Z] Container already running. Keep-alive process started.
[2024-01-25T00:45:00.700Z] @devcontainers/cli 0.54.1. Node.js v18.15.0. linux 6.5.13-1rodete1-amd64 x64.
[2024-01-25T00:45:00.700Z] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/home/user/code/vt-core --filter label=devcontainer.config_file=/home/user/code/vt-core/.devcontainer/python2/devcontainer.json
[2024-01-25T00:45:00.719Z] Stop (19 ms): Run: docker ps -q -a --filter label=devcontainer.local_folder=/home/user/code/vt-core --filter label=devcontainer.config_file=/home/user/code/vt-core/.devcontainer/python2/devcontainer.json
[2024-01-25T00:45:00.723Z] Stop (178 ms): Run: /usr/share/code/code --ms-enable-electron-run-as-node /home/user/.vscode/extensions/ms-vscode-remote.remote-containers-0.327.0/dist/spec-node/devContainersSpecCLI.js read-configuration --workspace-folder /home/user/code/vt-core --id-label devcontainer.local_folder=/home/user/code/vt-core --id-label devcontainer.config_file=/home/user/code/vt-core/.devcontainer/python2/devcontainer.json --log-level debug --log-format json --config /home/user/code/vt-core/.devcontainer/python2/devcontainer.json --mount-workspace-git-root
[2024-01-25T00:45:00.723Z] Start: Run: /usr/share/code/code --ms-enable-electron-run-as-node /home/user/.vscode/extensions/ms-vscode-remote.remote-containers-0.327.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /home/user/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder /tmp/devcontainers-94dca675-75a1-43b1-ac52-55612a5dff611706143500039 --workspace-folder /home/user/code/vt-core --workspace-mount-consistency cached --id-label devcontainer.local_folder=/home/user/code/vt-core --id-label devcontainer.config_file=/home/user/code/vt-core/.devcontainer/python2/devcontainer.json --log-level debug --log-format json --config /home/user/code/vt-core/.devcontainer/python2/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --mount type=bind,source=/run/user/1197791/wayland-0,target=/tmp/vscode-wayland-282df39b-1c6f-4f77-b2fd-2826e6780e30.sock --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root
[2024-01-25T00:45:00.869Z] @devcontainers/cli 0.54.1. Node.js v18.15.0. linux 6.5.13-1rodete1-amd64 x64.
[2024-01-25T00:45:00.869Z] Start: Run: docker buildx version
[2024-01-25T00:45:00.914Z] Stop (45 ms): Run: docker buildx version
[2024-01-25T00:45:00.914Z] github.com/docker/buildx v0.9.1-docker ed00243a0ce2a0aee75311b06e32d33b44729689
[2024-01-25T00:45:00.914Z] 
[2024-01-25T00:45:00.914Z] Start: Resolving Remote
[2024-01-25T00:45:00.919Z] Start: Run: docker-compose version --short
[2024-01-25T00:45:01.145Z] Stop (226 ms): Run: docker-compose version --short
[2024-01-25T00:45:01.145Z] Docker Compose version: 1.29.2
[2024-01-25T00:45:01.145Z] Start: Run: docker ps -q -a --filter label=com.docker.compose.project=vt-core_devcontainer --filter label=com.docker.compose.service=vt-core-py2
[2024-01-25T00:45:01.162Z] Stop (17 ms): Run: docker ps -q -a --filter label=com.docker.compose.project=vt-core_devcontainer --filter label=com.docker.compose.service=vt-core-py2
[2024-01-25T00:45:01.162Z] Start: Run: docker inspect --type container e7dc818a1a5b
[2024-01-25T00:45:01.179Z] Stop (17 ms): Run: docker inspect --type container e7dc818a1a5b
[2024-01-25T00:45:01.180Z] Start: Inspecting container
[2024-01-25T00:45:01.180Z] Start: Run: docker inspect --type container e7dc818a1a5bfb0926891b004914eeb18c86519ac38de943762732026444d655
[2024-01-25T00:45:01.195Z] Stop (15 ms): Run: docker inspect --type container e7dc818a1a5bfb0926891b004914eeb18c86519ac38de943762732026444d655
[2024-01-25T00:45:01.195Z] Stop (15 ms): Inspecting container
[2024-01-25T00:45:01.196Z] Start: Run in container: /bin/sh
[2024-01-25T00:45:01.199Z] Start: Run in container: uname -m
[2024-01-25T00:45:01.213Z] Stop (17 ms): Run in container: /bin/sh
[2024-01-25T00:45:01.213Z] Shell server terminated (code: 126, signal: null)
[2024-01-25T00:45:01.213Z] unable to find user vt-core: no matching entries in passwd file
[2024-01-25T00:45:01.213Z] Start: Run in container:  (command -v getent >/dev/null 2>&1 && getent passwd 'vt-core' || grep -E '^vt-core|^[^:]*:[^:]*:vt-core:' /etc/passwd || true)
[2024-01-25T00:45:01.213Z] Stdin closed!
[2024-01-25T00:45:01.215Z] Error: An error occurred setting up the container.
[2024-01-25T00:45:01.215Z]     at N$ (/home/user/.vscode/extensions/ms-vscode-remote.remote-containers-0.327.0/dist/spec-node/devContainersSpecCLI.js:409:3566)
[2024-01-25T00:45:01.215Z]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[2024-01-25T00:45:01.215Z]     at async tAA (/home/user/.vscode/extensions/ms-vscode-remote.remote-containers-0.327.0/dist/spec-node/devContainersSpecCLI.js:479:3833)
[2024-01-25T00:45:01.215Z]     at async CC (/home/user/.vscode/extensions/ms-vscode-remote.remote-containers-0.327.0/dist/spec-node/devContainersSpecCLI.js:479:4775)
[2024-01-25T00:45:01.215Z]     at async NeA (/home/user/.vscode/extensions/ms-vscode-remote.remote-containers-0.327.0/dist/spec-node/devContainersSpecCLI.js:612:11107)
[2024-01-25T00:45:01.215Z]     at async MeA (/home/user/.vscode/extensions/ms-vscode-remote.remote-containers-0.327.0/dist/spec-node/devContainersSpecCLI.js:612:10848)
[2024-01-25T00:45:01.219Z] Stop (496 ms): Run: /usr/share/code/code --ms-enable-electron-run-as-node /home/user/.vscode/extensions/ms-vscode-remote.remote-containers-0.327.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /home/user/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder /tmp/devcontainers-94dca675-75a1-43b1-ac52-55612a5dff611706143500039 --workspace-folder /home/user/code/vt-core --workspace-mount-consistency cached --id-label devcontainer.local_folder=/home/user/code/vt-core --id-label devcontainer.config_file=/home/user/code/vt-core/.devcontainer/python2/devcontainer.json --log-level debug --log-format json --config /home/user/code/vt-core/.devcontainer/python2/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --mount type=bind,source=/run/user/1197791/wayland-0,target=/tmp/vscode-wayland-282df39b-1c6f-4f77-b2fd-2826e6780e30.sock --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root
[2024-01-25T00:45:01.219Z] Exit code 1
[2024-01-25T00:45:01.221Z] Command failed: /usr/share/code/code --ms-enable-electron-run-as-node /home/user/.vscode/extensions/ms-vscode-remote.remote-containers-0.327.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /home/user/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder /tmp/devcontainers-94dca675-75a1-43b1-ac52-55612a5dff611706143500039 --workspace-folder /home/user/code/vt-core --workspace-mount-consistency cached --id-label devcontainer.local_folder=/home/user/code/vt-core --id-label devcontainer.config_file=/home/user/code/vt-core/.devcontainer/python2/devcontainer.json --log-level debug --log-format json --config /home/user/code/vt-core/.devcontainer/python2/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --mount type=bind,source=/run/user/1197791/wayland-0,target=/tmp/vscode-wayland-282df39b-1c6f-4f77-b2fd-2826e6780e30.sock --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root
[2024-01-25T00:45:01.221Z] Exit code 1

Steps to Reproduce:

  1. Build and reopen in container. Choose python2/python3
  2. Switch to container. Choose python3/python2

The docker-compose.yaml:

version: '3'
services:
  vt-core-py2:
    build:
      context: ../
      dockerfile: .devcontainer/python2/Dockerfile
    volumes:
      - ..:/workspaces/vt-core:cached
    command: sleep infinity
    extra_hosts:
      - "host.docker.internal:host-gateway"

  vt-core-py3:
    build:
      context: ../
      dockerfile: .devcontainer/python3/Dockerfile
    volumes:
      - ..:/workspaces/vt-core:cached
    command: sleep infinity
    extra_hosts:
      - "host.docker.internal:host-gateway"

For the the devcontainer.json I use the following two:

  • .devcontainer/python2/devcontainer.json:
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/debian
{
	"name": "VT Core python2 devcontainer",
	// Use image, a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
  "dockerComposeFile": [
    "../docker-compose.yaml"
  ],
  "service": "vt-core-py2",
  "shutdownAction": "none",
	"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
	// Features to add to the dev container. More info: https://containers.dev/features.
	"features": {
    "ghcr.io/devcontainers/features/common-utils:2": {
			"user": "vt-core"
		},
		"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {},
		"ghcr.io/devcontainers/features/git:1": {
			"version": "2.42.0"
		}
	},
	"mounts": [
		"source=${env:HOME}/.config/gcloud,target=/home/vt-core/.config/gcloud,type=bind,consistency=cached"
	],
	// Use 'forwardPorts' to make a list of ports inside the container available locally.
	// "forwardPorts": [],
	"containerEnv": {
		"GAE_SDK_ROOT": "/usr/lib/google-cloud-sdk/platform/google_appengine/",
		"ELASTIC_OVH_IMAGE": "docker.elastic.co/elasticsearch/elasticsearch:6.8.23",
		"ELASTICSEARCH_OVH": "http://host.docker.internal:9200",
		"OPENSEARCH": "http://host.docker.internal:9300",
		"LOCAL_ELASTICSEARCH": "1",
		"DEVCONTAINER_ENV": "true"
	},
  "remoteEnv": {
    "PYTHONPATH": "${containerEnv:GAE_SDK_ROOT}"
  },
	// Configure tool-specific properties.
	"customizations": {
		"vscode": {
			"settings": {
        "terminal.integrated.defaultProfile.linux": "zsh",
        "python.pythonPath": "/usr/local/bin/python2",
        "python.defaultInterpreterPath": "/usr/local/bin/python2",
        "python.formatting.provider": "yapf",
        "python.formatting.yapfArgs": [
          "--style",
          "{based_on_style: google, indent_width: 2}"
        ],
        "python.formatting.yapfPath": "/home/vt-core/.local/bin/yapf",
        "editor.rulers": [
          80
        ],
        "editor.formatOnPaste": true,
        "editor.formatOnType": true,
        "editor.tabSize": 2,
        "editor.useTabStops": false,
        "editor.wrappingIndent": "deepIndent",
        "editor.codeActionsOnSave": {
          "source.organizeImports": true
        }
      },
			"extensions": [
        // The latest python extension with support for python2
        "[email protected]",
        // The latest pylance extension with support for [email protected]. Can be removed when we upgrade to python 3
        "[email protected]",
        "njpwerner.autodocstring",
        "eamodio.gitlens",
        "GoogleCloudTools.cloudcode"
			]
		}
	},
	"postCreateCommand": ".devcontainer/python2/post-create-command.sh",
	// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
	"remoteUser": "vt-core"
}
  • .devcontainer/python3/devcontainer.json
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/debian
{
	"name": "VT Core python3 devcontainer",
	// Use image, a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
  "dockerComposeFile": [
    "../docker-compose.yaml"
  ],
  "service": "vt-core-py3",
  "shutdownAction": "none",
  "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
	// Features to add to the dev container. More info: https://containers.dev/features.
	"features": {
    "ghcr.io/devcontainers/features/common-utils:2": {
			"user": "vt-core"
		},
		"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {},
    "ghcr.io/devcontainers/features/python:1": {
      "version": "3.10"
    }
	},
	"mounts": [
		"source=${env:HOME}/.config/gcloud,target=/home/vt-core/.config/gcloud,type=bind,consistency=cached"
	],
	// Use 'forwardPorts' to make a list of ports inside the container available locally.
	// "forwardPorts": [],
	"containerEnv": {
		"GAE_SDK_ROOT": "/usr/lib/google-cloud-sdk/platform/google_appengine/",
		"ELASTIC_OVH_IMAGE": "docker.elastic.co/elasticsearch/elasticsearch:6.8.23",
		"ELASTICSEARCH_OVH": "http://host.docker.internal:9200",
		"OPENSEARCH": "http://host.docker.internal:9300",
		"LOCAL_ELASTICSEARCH": "1",
		"DEVCONTAINER_ENV": "true"
	},
  "remoteEnv": {
    "PYTHONPATH": "${containerEnv:GAE_SDK_ROOT}/lib/third_party/httplib2/python3/:${containerEnv:GAE_SDK_ROOT}/platform/google_appengine:${containerEnv:GAE_SDK_ROOT}/platform/google_appengine/lib"
  },
	// Configure tool-specific properties.
	"customizations": {
		"vscode": {
			"settings": {
				"terminal.integrated.defaultProfile.linux": "zsh",
        "python.formatting.provider": "none",
        "python.defaultInterpreterPath": "/usr/local/python/current/bin/python",
        "python.testing.pytestArgs": [
          "tests"
        ],
        "python.testing.unittestEnabled": false,
        "python.testing.pytestEnabled": true,
				"[python]": {
          "editor.formatOnSaveMode": "modifications",
          "editor.formatOnSave": true,
          "editor.defaultFormatter": "eeyore.yapf",
          "editor.formatOnType": false,
          "yapf.args": [
            "--style",
            "{based_on_style: google, indent_width: 2}"
          ]
        },
				"editor.rulers": [
					80
				],
				"editor.formatOnPaste": true,
				"editor.formatOnType": true,
				"editor.tabSize": 2,
				"editor.useTabStops": false,
				"editor.wrappingIndent": "deepIndent",
				"editor.codeActionsOnSave": {
					"source.organizeImports": true
				}
			},
			"extensions": [
        "ms-python.python",
        "ms-python.pylint",
        "ms-python.isort",
        "ms-python.mypy",
        "eeyore.yapf",
        "njpwerner.autodocstring",
        "eamodio.gitlens",
        "GoogleCloudTools.cloudcode"
			]
		}
	},
	"postCreateCommand": ".devcontainer/python3/post-create-command.sh",
	// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
	"remoteUser": "vt-core"
}

The Dockerfile to build both images is:

FROM python:2
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && \
    apt-get -y install \
        curl \
        git \
        gcc \
        apt-transport-https ca-certificates gnupg && \
    echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \
    curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && \
    apt-get update && apt-get install \
        google-cloud-cli \
        google-cloud-cli-app-engine-python \
        google-cloud-cli-app-engine-python-extras && \
    apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*

Python3 is same image but using python devcontainer feature to install python3.10

@vscodenpa vscodenpa added the containers Issue in vscode-remote containers label Jan 25, 2024
@pjonsson
Copy link

@raulbocanegra https://github.com/devcontainers/features/tree/main/src/common-utils lists the option as username, not user?

@raulbocanegra
Copy link
Author

raulbocanegra commented Feb 27, 2024

Hi @pjonsson and thanks for pointing that out. Either with "user" or "username" the user in the container is correctly created. It only fails when trying to switch between containers. I can build both containers and use them but without switching.

@raulbocanegra
Copy link
Author

It is like devcontainer features only got installed on the first container you choose when opening the project. So if you switch from one to another the common-utils feature has not created the user.

@chrmarti
Copy link
Contributor

This is expected. Only one of the compose services is built as dev container.

@chrmarti chrmarti added the feature-request Request for new features or functionality label Dec 13, 2024
@vs-code-engineering vs-code-engineering bot added this to the Backlog Candidates milestone Dec 13, 2024
Copy link

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 10 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

Copy link

This feature request has not yet received the 10 community upvotes it takes to make to our backlog. 10 days to go. To learn more about how we handle feature requests, please see our documentation.

Happy Coding

Copy link

🙁 In the last 60 days, this feature request has received less than 10 community upvotes and we closed it. Still a big Thank You to you for taking the time to create this issue! To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@vs-code-engineering vs-code-engineering bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
containers Issue in vscode-remote containers feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

4 participants