Steps to Reproduce:
Dockerfile with user different than rootRUN usermod -u 1020 application
USER application
Remote Containers: Attach to running container...Setting up container with 575f427ee0eab56f3e140dda2aabd89fd80a2e7ab48795e0532d728e73694333
Run: docker exec 575f427ee0eab56f3e140dda2aabd89fd80a2e7ab48795e0532d728e73694333 /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 exec 575f427ee0eab56f3e140dda2aabd89fd80a2e7ab48795e0532d728e73694333 test -d /root/.vscode-remote/bin/473af338e1bd9ad4d9853933da1cd9d5d9e07dc9
Installing VS Code Server for commit 473af338e1bd9ad4d9853933da1cd9d5d9e07dc9
Run: docker exec 575f427ee0eab56f3e140dda2aabd89fd80a2e7ab48795e0532d728e73694333 mkdir -p /root/.vscode-remote/bin/473af338e1bd9ad4d9853933da1cd9d5d9e07dc9_1556829785420
mkdir: cannot create directory ‘/root’: Permission denied
Command failed: docker exec 575f427ee0eab56f3e140dda2aabd89fd80a2e7ab48795e0532d728e73694333 mkdir -p /root/.vscode-remote/bin/473af338e1bd9ad4d9853933da1cd9d5d9e07dc9_1556829785420
That's because the user specified in Dockerfile can't create directories in /root. Is there a way for vscode to select different path than /root/.vscode-remote?
@threaz It will respect whatever HOME is set to, so this will work:
ARG USERNAME=user-name-goes-here
RUN useradd -m $USERNAME
ENV HOME /home/$USERNAME
# [Optional] Add sudo support
RUN apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME && \
chmod 0440 /etc/sudoers.d/$USERNAME
# ** Anything else you want to do like clean up goes here **
USER $USERNAME
Does this solve your issue?
I'm having the exact same issue but I don't have access to modify the Dockerfile of the container image, which doesn't specify a HOME. Is there any other way around this? Thanks.
Thanks for your response @Chuxel. Specifying ENV HOME /home/$USERNAME has helped indeed. I was kind of confused, because $HOME was already set to correct value, but it seems code expects explicit statement in Dockerfile.
Ideally we would find out what the home folder is from within the container without relying on HOME on the container's or image's inspect data. For now setting HOME with ENV in the Dockerfile is the correct workaround. (Changed title to reflect this.)
I am having the same issue. I don't have access to the DockerFile.
Here's a dirty workaround that worked for me:
sudo service docker stopHOME=/home/vijay609 to the ENV section.sudo service docker start@javierdihu and @vijay609: if you don't have access to the Dockerfile, you can still work around this. If you're working on a "bare" docker setup, you can use something like the following in your devcontainer.json:
{
...
"runArgs": [ "--env", "HOME=/home/yourusername" ]
}
If you're using docker-compose, than you'd need something like:
{
"dockerComposeFile": [
"path/to/your/base/docker-compose.yml",
"docker-compose.extend.yml"
],
"service": "yourservice",
...
}
and inside .devcontainer/docker-compose.extend.yml:
services:
yourservice:
environment:
HOME: /home/yourusername
disclaimer: I only tested the docker-compose approach, but the bare docker one should work just as well.
@vijay609 Thanks for the tip. Note that this doesn't work if the container was started with --rm as it will be deleted upon stopping the docker service.
@chrmarti Why not install in /tmp? Out of curiosity, what are you installing inside the image anyway?
@nickolai-voyage educated guess: because /tmp is frequently mounted as tmpfs with noexec. Attempting to find a $HOME seems less error-prone (from my admittedly uninformed perspective).
@nickolai-voyage We install the VS Code Server. Using the user's home folder seemed to make the most sense since that is also owned by the same user (which is not necessarily root), we also place settings and extensions in ~/.vscode-remote.
Seems a good idea @chrmarti and doing what @costela said resolved the problem.
I just added
HOME: /home/yourusername
in environnment for the service where vscode remote will enter.
Running the container with docker run -e HOME=/user/yourusername also works. It would be nice if there was a helpful warning message, even better additionally a configuration option "remote-containers.home".
We now read the home folder from /etc/passwd. (Available in 0.60.0, which currently requires VS Code Insiders to install.)
@SoftwareApe Would this potentially be possible with something like docker-compose up -e HOME=/user/yourusername?
I've tried adding the mentioned solutions to my dockerfile or docker-compose.yml but still get the no access to root message. :(
@MojoJojo86 Would using the home folder from /etc/passwd help? If so, could you give the VS Code Insiders build a try? That gets a newer version of the Remote Containers extension.
@MojoJojo86 thank you, the home folder trick works on stable!
@chrmarti Cheers I tried the insiders edition and that worked.
Most helpful comment
@threaz It will respect whatever HOME is set to, so this will work:
Does this solve your issue?