I am trying to create a docker container to use as my remote development container. I keep getting an error, and I'm not sure how to resolve it. If I don't set the "remoteUser": "developer"
setting in the devcontainer.json file, then it works because it isn't attempting to run the development container as the remote user. I don't want to run the development container as root though.
mkdir: cannot create directory '/home/developer': Permission denied
Dockerfile:
FROM ubuntu:latest
# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get -y update \
&& apt-get -y install --no-install-recommends apt-utils dialog git wget \
#
# Add remote development (developer) group/user.
&& groupadd -g 1000 -o developer \
&& useradd -u 1000 -g 1000 developer \
#
# 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=dialog
Full Output:
[18 ms] Start: Resolving remote
[20 ms] Setting up container for folder or workspace: C:\Repos\Sample
[21 ms] Start: Check Docker is running
[21 ms] Start: Run: docker info
[666 ms] Start: Run: docker ps -q -a --filter label=vsch.local.folder=C:\Repos\Sample --filter label=vsch.quality=stable
[1087 ms] Start: Run: docker inspect --type container 1739eb19eccb
[1504 ms] Start: Starting container
[1504 ms] Start: Run: docker start 1739eb19eccb79a4c0c6390275caf5224c0b5d94385ee28064a8fb504704c12a
[3063 ms] Start: Run: docker ps -q -a --filter label=vsch.local.folder=C:\Repos\Sample --filter label=vsch.quality=stable
[3503 ms] Start: Run: docker inspect --type container 1739eb19eccb
[3915 ms] Start: Inspecting container
[3916 ms] Start: Run: docker inspect --type container 1739eb19eccb79a4c0c6390275caf5224c0b5d94385ee28064a8fb504704c12a
[4342 ms] Start: Run: docker exec -i -u developer -e VSCODE_REMOTE_CONTAINERS_SESSION=34411177-6cf8-408f-8914-a454274269cf1601787357110 1739eb19eccb79a4c0c6390275caf5224c0b5d94385ee28064a8fb504704c12a /bin/sh
[4352 ms] Start: Run in container: uname -m
[5739 ms] x86_64
[5740 ms]
[5740 ms] Start: Run in container: (cat /etc/os-release || cat /usr/lib/os-release) 2>/dev/null
[5743 ms] NAME="Ubuntu"
VERSION="20.04.1 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.1 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
[5744 ms]
[5744 ms] Start: Run in container: cat /etc/passwd
[5748 ms] Start: Setup shutdown monitor
[5754 ms] Forking shutdown monitor: c:\Users\michael\.vscode\extensions\ms-vscode-remote.remote-containers-0.140.1\dist\shutdownMonitorProcess \\.\pipe\vscode-remote-containers-035ad203a5af805d0d3da68a329a3c395d0dd338-sock singleContainer Info c:\Users\michael\AppData\Roaming\Code\logs\20201003T145211\exthost1\ms-vscode-remote.remote-containers
[5772 ms] Start: Run in container: test -d /home/developer/.vscode-server
[5778 ms]
[5778 ms]
[5778 ms] Exit code 1
[5779 ms] Start: Run in container: test -d /home/developer/.vscode-remote
[5790 ms]
[5791 ms]
[5791 ms] Exit code 1
[5791 ms] Start: Run in container: set -o noclobber ; mkdir -p '/home/developer/.vscode-server/data/Machine' && { > '/home/developer/.vscode-server/data/Machine/.writeMachineSettingsMarker' ; } 2> /dev/null
[5796 ms]
[5796 ms] mkdir: cannot create directory '/home/developer': Permission denied
[5796 ms] Exit code 1
[5797 ms] Start: Run in container: test -d /home/developer/.vscode-server/bin/2af051012b66169dde0c4dfae3f5ef48f787ff69
[5799 ms]
[5800 ms]
[5800 ms] Exit code 1
[5800 ms] Installing VS Code Server for commit 2af051012b66169dde0c4dfae3f5ef48f787ff69
[5800 ms] Start: Run in container: mkdir -p /home/developer/.vscode-server/bin/2af051012b66169dde0c4dfae3f5ef48f787ff69_1601787364083
[5815 ms]
[5815 ms] mkdir: cannot create directory '/home/developer': Permission denied
[5815 ms] Exit code 1
[5818 ms] Command in container failed: mkdir -p /home/developer/.vscode-server/bin/2af051012b66169dde0c4dfae3f5ef48f787ff69_1601787364083
The command
useradd -u 1000 -g 1000 developer
doesn't create the users home directory. The/home
is owned by theroot
user so after youdocker exec
into the container as the unprivilegeddeveloper
user and attempt to create directories under the/home
directory you get "Permission Denied".You can create the users home directory with the correct permissions by amending the
useradd
command:useradd -u 1000 -d /home/developer -m -k /etc/skel -g 1000 developer
.Extracts from the
useradd
man
pages:-d
: The new user will be created usingHOME_DIR
as the value for the user's login directory. The default is to append theLOGIN
name toBASE_DIR
and use that as the login directory name. The directoryHOME_DIR
does not have to exist but will not be created if it is missing.-m
: Create the user's home directory if it does not exist. The files and directories contained in the skeleton directory (which can be defined with the-k
option) will be copied to the home directory.-k
: The skeleton directory, which contains files and directories to be copied in the user's home directory, when the home directory is created byuseradd
.