在从 vscode 启动容器时无法连接到 "workspaceMount"

cannot connect to "workspaceMount" at container launch from vscode

使用 vscode 和 wsl2,我尝试使用默认方法启动一个容器,没有自定义。这产生了与下面相同的错误。

所以按照 vscode 文档我在 devcontainer.json

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

I select Reopen in container,启动顺序发生但产生错误

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

日志错误为

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

通过从 docker 桌面启动容器,我可以确认

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

这个问题是由于所有者 root:root 造成的吗?

是否应该在 Dokerfile 中通过 chown 更改?如果可以,您能否提供一个示例代码来执行此操作,是 RUN chown ...?

我想您已按照 https://code.visualstudio.com/docs/remote/containers-advanced

中的文档进行操作

源应包含子文件夹“myRepo”,目标仅包含“workspaces”

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