How to change default volume mount in VS Code Remote Container?

五迷三道 提交于 2019-12-11 03:19:57

问题


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

As well as my .devcontainer.json:

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

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


回答1:


Update

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


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

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



来源:https://stackoverflow.com/questions/55970168/how-to-change-default-volume-mount-in-vs-code-remote-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!