如何更改VS Code远程容器中的默认卷安装? [英] How to change default volume mount in VS Code Remote Container?

查看:133
本文介绍了如何更改VS Code远程容器中的默认卷安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改容器中打开的文件夹的默认卷安装?我已经在Dockerfile中尝试过:

How to change the default volume mount for the folder opened in the container? I have tried in my Dockerfile:

RUN mkdir /root/myproject
WORKDIR /root/myproject

和我的.devcontainer.json:

{
    "name": "My Project",
    "dockerFile": "Dockerfile",
    "workspaceFolder": "/root/myproject",
}

但是文件夹仍在容器内的/workspaces/myproject上.

But the folder is still being mounted on /workspaces/myproject within the container.

推荐答案

更新

即将显示的vscode-container版本应支持使用workspaceFolder,如您所显示.有关详细信息,请参见此问题.

The upcoming vscode-container release should support using workspaceFolder as you show. See this issue for details.

如果使用的是远程扩展的较旧版本,则在使用单个dockerfile时无法执行此操作,但是可以对workspaceFolder设置来执行此操作code.visualstudio.com/docs/remote/containers#_extending-your-docker-compose-file-for-development"rel =" nofollow noreferrer> docker-compose开发容器:

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

这篇关于如何更改VS Code远程容器中的默认卷安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆