更新时间:2022-12-06 11:40:50
更新
即将显示的vscode-container版本应支持使用workspaceFolder
,如您所显示.有关详细信息,请参见此问题.
The upcoming vscode-container release should support using workspaceFolder
as you show. See this issue for details.
如果使用的是远程扩展的较旧版本,则在使用单个dockerfile时无法执行此操作,但是可以对
If you are using an older version of the remote extensions, it is not possible to do this when using a single dockerfile, but you can do this using the workspaceFolder
setting for a docker-compose dev container:
.devcontainer/devcontainer.json
:
{
"name": "My Project",
"dockerComposeFile": "docker-compose.yml",
"service": "my-service-name",
"workspaceFolder": "/customPath"
}
.devcontainer/docker-compose.yml
:
version: '3'
services:
my-service-name:
build:
context: .
dockerfile: Dockerfile
volumes:
- ..:/customPath
command: sleep infinity
您可以将customPath
更改为要将工作空间安装到的任何路径.另外,请确保添加command: sleep infinity
以便容器在启动时会自动关闭
You can change customPath
to whatever path you would like the workspace to be mounted to. Also, make sure to add the command: sleep infinity
for containers would automatically shutdown when started