Open single Dev Container from a Multi Folder VS Code Workspace

100 Views Asked by At

I want to build my devcontainers from a VSCode multi-folder workspace.

Currently I have 1 Python project I am trying to get up and running in the workspace. However, when the dev container loads, I get a "Workspace does not exist". The problem only manifests if I open the code workspace. If I just open the root container all is fine.

I suspect the problem is in the way the initial VSCode workspace is opened. It will try and apply the same workspace onto the container. So trying to open a folder on the container from a multi folder code workspace is not supported or does not work.

Motivation

The motivation here is to have a single control across my Python repos - where I can define my common code quality settings once - and share across these repos - instead of duplicating across projects. So I just trying to get a single devcontainer up in this setup.

Setup

I have a VSCode multi folder workspace docker.dev.code-workspace:

{
    "folders": [
        {
            "path": "."
        },
        {
            "path": "sources/service-a"
        }
    ],
    "settings": {}
}

My folder structure is:

├───.devcontainer
│   └───service-a
│       ├───dev.dockerfile
|       └───devcontainer.json
├───.vscode
├───sources
│   └───service-a
│       └───sources
└───standards
    └───python

dev.dockerfile

FROM python:3.11-bullseye

# custom stuff

devcontainer.json

{
  "name": "Service A Development",
  "build": {
    "context": ".",
    "dockerfile": "./dev.dockerfile"
  },
  "workspaceMount": "source=${localWorkspaceFolder}/sources/service-a,target=/workspace,type=bind,consistency=cached",
  "workspaceFolder": "/workspace",
  "mounts": [
    "source=${localWorkspaceFolder}/standards/python/settings.json,target=/workspace/.vscode/settings.json,type=bind,consistency=cached"
  ]
}

Somewhat trying to do connect-multiple-containers without the docker-compose.

Issue

When I choose Dev Containers: Rebuild and Reopen in Container I get the error:

Workspace does not exist

The problem only manifests if I open the code workspace.

I get the same issue if I move to a docker compose setup.

The Ask

I was hoping to trigger opening the single container from a multi folder workspace like I have configured above.

Workarounds

If I just open the root docker.dev folder in VSCode then the Rebuild and Reopen in Container runs perfectly.

Docker compose scenario also works fine if I open the folder and not the code workspace.

0

There are 0 best solutions below