首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将devcontainer挂载到$HOME

如何将devcontainer挂载到$HOME
EN

Stack Overflow用户
提问于 2019-10-09 09:54:03
回答 1查看 593关注 0票数 1

我正在尝试设置一个devcontainer,它将VSCode中的工作区挂载到/home/node中,并将项目中的所有内容放入docker中的$HOME中。

我想这样做的原因是,当项目安装到docker中时,我将所有内容都包含在我正在处理的单个项目中。

当使用此配置运行时,我得到一个错误。

有谁有关于如何实现这一点的建议吗?

这是我的devcontainer.json

代码语言:javascript
复制
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at
// https://github.com/microsoft/vscode-dev-containers/tree/master/containers/typescript-node-lts
{
  "name": "Node.js (latest LTS) & TypeScript",
  "dockerFile": "Dockerfile",
  // Use 'settings' to set *default* container specific settings.json values on container create.
  // You can edit these settings after create using File > Preferences > Settings > Remote.
  "settings": {
    "terminal.integrated.shell.linux": "/bin/bash"
  },
  // Uncomment the next line if you want to publish any ports.
  "appPort": [3000, 8000, 6006],
  // Uncomment the next line to run commands after the container is created.
  "postCreateCommand": "mkdir ~/.ssh && cp .ssh/* ~/.ssh && chmod 600 ~/.ssh/id_rsa",
  // Uncomment the next line to use a non-root user. On Linux, this will prevent
  // new files getting created as root, but you may need to update the USER_UID
  // and USER_GID in .devcontainer/Dockerfile to match your user if not 1000.
  "runArgs": ["-u", "node"],
  // Add the IDs of extensions you want installed when the container is created in the array below.
  "extensions": [
    "dbaeumer.vscode-eslint",
    "esbenp.prettier-vscode",
    "Orta.vscode-jest"
  ],
  "workspaceMount": "src=/home/node,dst=/home/node,type=volume,volume-driver=local",
  "workspaceFolder": "/home/node"
}

和我的Dockerfile

代码语言:javascript
复制
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------

FROM node:lts

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# The node image comes with a base non-root 'node' user which this Dockerfile
# gives sudo access. However, for Linux, this user's GID/UID must match your local
# user UID/GID to avoid permission issues with bind mounts. Update USER_UID / USER_GID 
# if yours is not 1000. See https://aka.ms/vscode-remote/containers/non-root-user.
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Configure apt and install packages
RUN apt-get update \
    && apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \ 
    #
    # Verify git and needed tools are installed
    && apt-get -y install git iproute2 procps \
    #
    # Remove outdated yarn from /opt and install via package 
    # so it can be easily updated via apt-get upgrade yarn
    && rm -rf /opt/yarn-* \
    && rm -f /usr/local/bin/yarn \
    && rm -f /usr/local/bin/yarnpkg \
    && apt-get install -y curl apt-transport-https lsb-release \
    && curl -sS https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/pubkey.gpg | apt-key add - 2>/dev/null \
    && echo "deb https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
    && apt-get update \
    && apt-get -y install --no-install-recommends yarn \
    #
    # Install tools globally
    && npm install -g jest prettier eslint typescript localtunnel \
    #
    # [Optional] Update a non-root user to match UID/GID - see https://aka.ms/vscode-remote/containers/non-root-user.
    && if [ "$USER_GID" != "1000" ]; then groupmod node --gid $USER_GID; fi \
    && if [ "$USER_UID" != "1000" ]; then usermod --uid $USER_UID node; fi \
    # [Optional] Add add sudo support for non-root user
    && apt-get install -y sudo \
    && echo node ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/node \
    && chmod 0440 /etc/sudoers.d/node \
    #
    # Clean up
    && apt-get autoremove -y \
    && apt-get clean -y \
    && rm -rf /var/lib/apt/lists/*

# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=
EN

回答 1

Stack Overflow用户

发布于 2020-05-06 07:28:19

不是100%确定的,因为你没有分享你造成的错误,但这可能是因为你使用:

"workspaceMount":"src=/home/node,dst=/home/node,type=卷驱动程序,-=本地“,

当它在你的情况下不是“卷”的时候。这里的类型应该是“bind”。

有关详细信息,请参阅here

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58296032

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档