Visual studio code 如何将devcontainer装载到$HOME

Visual studio code 如何将devcontainer装载到$HOME,visual-studio-code,Visual Studio Code,我正在尝试设置一个devcontainer,它将VSCode中的工作区装载到/home/node,并将项目中的所有内容放入docker中的$home中 我之所以想这样做,是因为当项目装载到docker中时,我将所有内容都包含在我正在处理的各个项目中 使用此配置运行时,我收到一个错误 有人对如何实现这一目标有什么建议吗 这是我的devcontainer.json // For format details, see https://aka.ms/vscode-remote/devcontainer

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

我之所以想这样做,是因为当项目装载到docker中时,我将所有内容都包含在我正在处理的各个项目中

使用此配置运行时,我收到一个错误

有人对如何实现这一目标有什么建议吗

这是我的devcontainer.json

// 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

#-------------------------------------------------------------------------------------------------------------
# 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=

不是100%确定,因为您没有分享遇到的错误,但是 这可能是因为您使用:

“workspaceMount”:“src=/home/node,dst=/home/node,type=volume,volume driver=local”

当它不是您的“卷”时。此处的类型应为“bind”

有关更多信息,请参阅