Search code examples
visual-studio-codedockerfilevscode-devcontainer

cannot connect to "workspaceMount" at container launch from vscode


using vscode and wsl2, I have tried to launch a container using the default method and no customization. This generated the same error as below.

so following vscode docs I set a "workspaceMount" in devcontainer.json

"workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/myRepo,type=bind,consistency=delegated",
"workspaceFolder": "/workspaces",

I select Reopen in container, the launch sequence happens but an error is generated

a mount config is invalid, make sure it has the right format and a source folder that exists on the machine where the Docker daemon is running

the log error is

Command failed: docker run -a STDOUT -a STDERR --mount source=d:\git\myRepo,target=/workspaces/myRepo,type=bind,consistency=delegated --mount type=volume,src=vscode,dst=/vscode -l vsch.quality=stable -l vsch.remote.devPort=0 -l vsch.local.folder=d:\git\myRepo --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --entrypoint /bin/sh vsc-myRepo-a878aa9edbcf04f717c76e764dabcde6 -c echo Container started ; trap "exit 0" 15; while sleep 1 & wait $!; do :; done

by launching the container from docker desktop I can confirm

cd /workspaces
ls -l 
drwxr-xr-x 2 root root 4096 Dec  3 11:48 myRepo

Is this issue due to owner root:root ?

Should this be changed by chown in the Dokerfile? if so could you provide a sample code to do this, is it by RUN chown ...?


Solution

  • I guess you followed the documentation in https://code.visualstudio.com/docs/remote/containers-advanced

    The source should contains the subfolder "myRepo" and the target only "workspaces"

    "workspaceMount": "source=${localWorkspaceFolder}/myRepo,target=/workspaces,type=bind,consistency=delegated",
    "workspaceFolder": "/workspaces",