在VSCode中将devcontainer.json设置为非root用户

时间:2019-11-01 19:40:17

标签: linux docker visual-studio-code conda

我正在尝试将VSCode设置为使用docker容器进行远程开发,但是尝试在容器中安装vscode-server时仍然存在权限问题。

Setting up container for folder or workspace: /home/username/4NN3-Neural-Networks-and-Deep-Learning
Run: docker exec 9181871e4be347ece95c47cce6ec717d8cce9d8e2febe3fd3e7ea98984a434db /bin/sh -c (cat /etc/os-release || cat /usr/lib/os-release) 2>/dev/null
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
Run: docker cp 9181871e4be347ece95c47cce6ec717d8cce9d8e2febe3fd3e7ea98984a434db:/etc/passwd -
Forking shutdown monitor: /home/username/.vscode/extensions/ms-vscode-remote.remote-containers-0.81.1/dist/shutdownMonitorProcess /run/user/1001/snap.code/vscode-remote-containers-a2996f7f87a405d00b1db59d2b1d8d9b31ef07dc.sock singleContainer no-trace
Run: docker exec 9181871e4be347ece95c47cce6ec717d8cce9d8e2febe3fd3e7ea98984a434db test -d /home/username/.vscode-server
Run: docker exec 9181871e4be347ece95c47cce6ec717d8cce9d8e2febe3fd3e7ea98984a434db test -d /home/username/.vscode-remote
Run: docker exec 9181871e4be347ece95c47cce6ec717d8cce9d8e2febe3fd3e7ea98984a434db /bin/sh -c set -o noclobber ; mkdir -p '/home/username/.vscode-server/data/Machine' && { > '/home/username/.vscode-server/data/Machine/.writeMachineSettingsMarker' ; } 2> /dev/null
mkdir: cannot create directory ‘/home/username/.vscode-server’: Permission denied
Run: docker exec 9181871e4be347ece95c47cce6ec717d8cce9d8e2febe3fd3e7ea98984a434db /bin/sh -c set -o noclobber ; mkdir -p '/home/username/.vscode-server/data/Machine' && { > '/home/username/.vscode-server/data/Machine/.copyGitConfigMarker' ; } 2> /dev/null
mkdir: cannot create directory ‘/home/username/.vscode-server’: Permission denied
Run: docker exec 9181871e4be347ece95c47cce6ec717d8cce9d8e2febe3fd3e7ea98984a434db test -d /home/username/.vscode-server/bin/6ab598523be7a800d7f3eb4d92d7ab9a66069390
Installing VS Code Server for commit 6ab598523be7a800d7f3eb4d92d7ab9a66069390
Run: docker exec 9181871e4be347ece95c47cce6ec717d8cce9d8e2febe3fd3e7ea98984a434db mkdir -p /home/username/.vscode-server/bin/6ab598523be7a800d7f3eb4d92d7ab9a66069390_1572636263815
mkdir: cannot create directory ‘/home/username/.vscode-server’: Permission denied

我的Dockerfile在下面:

FROM tiangolo/python-machine-learning:python3.6

LABEL version="1.0"
LABEL description="Dev Environment for McMaster University, SFWRTECH 4NN3 Course"

# Update Conda
RUN conda update -n base -c defaults conda

# Install ML Libraries  
RUN conda install -y tensorflow
RUN conda install -y keras
RUN conda install -y numpy
RUN conda install -y scipy
RUN conda install -y scikit-learn
RUN conda install -y pandas
RUN conda install -y matplotlib
RUN conda install -y pylint

# Creating New User and Set Password
RUN useradd --create-home --shell /bin/bash username
RUN echo 'username:passw0rd' | chpasswd

# Set User & WORKDIR
USER username
ENV HOME /home/username
WORKDIR /home/username

从常规终端中的映像创建的容器运行良好。这似乎是一个反复出现的问题,我已经尝试了在github herehere中的问题跟踪器中提出的一些解决方案,都提议将$HOME设置为/home/username。 / p>

我在$HOMEDockerfile中都设置了devcontainer.json,但是问题仍然存在,有人对此有解决方法吗?

devcontainer.json在下面:

{
    "name": "4NN3 Dev Container",
    // Sets the run context to one level up instead of the .devcontainer folder.
    "context": "..",
    // "dockerFile": "../Dockerfile",
    "image": "4nn3-mcmaster",

    "runArgs": [
        // See https://aka.ms/vscode-remote/containers/non-root-user
        // "-u", "username"
        "--env", "HOME=/home/username/"
    ],

    "settings": {
        "terminal.integrated.shell.linux": null
    },

    "workspaceMount": "src=${localWorkspaceFolder}/,dst=/home/username/,type=bind,consistency=delegated",
    "workspaceFolder": "/home/username/",

    "extensions": ["ms-python.python", "eamodio.gitlens"]
}

0 个答案:

没有答案