Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determine install folder from within the container #22

Closed
threaz opened this issue May 2, 2019 · 17 comments
Closed

Determine install folder from within the container #22

threaz opened this issue May 2, 2019 · 17 comments
Assignees
Labels
containers Issue in vscode-remote containers plan-item A plan item
Milestone

Comments

@threaz
Copy link

threaz commented May 2, 2019

  • VSCode Version: 1.34.0-insider
  • Local OS Version: macOS Mojave
  • Remote OS Version: Debian Stretch
  • Remote Extension/Connection Type: Docker

Steps to Reproduce:

  1. Create Dockerfile with user different than root
RUN usermod -u 1020 application
USER application
  1. Run container
  2. Run Remote Containers: Attach to running container...
  3. Select container you want to attach to
  4. Setup process fails with the following error:
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?

@Chuxel
Copy link
Member

Chuxel commented May 2, 2019

@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?

@Chuxel Chuxel added containers Issue in vscode-remote containers info-needed Issue requires more information from poster labels May 2, 2019
@javierdihu
Copy link

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.

@chrmarti chrmarti changed the title Permission denied during attaching Add option to override install directory May 3, 2019
@chrmarti chrmarti added feature-request Request for new features or functionality and removed info-needed Issue requires more information from poster labels May 3, 2019
@threaz
Copy link
Author

threaz commented May 3, 2019

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.

@chrmarti chrmarti changed the title Add option to override install directory Determine install folder from within the container May 3, 2019
@chrmarti
Copy link
Contributor

chrmarti commented May 3, 2019

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.)

@vijay609
Copy link

vijay609 commented May 17, 2019

I am having the same issue. I don't have access to the DockerFile.
Here's a dirty workaround that worked for me:

  1. Stop dockerd sudo service docker stop
  2. open /var/lib/docker/containers/[container-id]/config.v2.json file and add HOME=/home/vijay609 to the ENV section.
  3. restart dockerd sudo service docker start
  4. Attach to container from vscode.

@costela
Copy link

costela commented May 17, 2019

@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.

@nickolai-voyage
Copy link

@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.

@nickolai-voyage
Copy link

@chrmarti Why not install in /tmp? Out of curiosity, what are you installing inside the image anyway?

@costela
Copy link

costela commented May 21, 2019

@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).

@chrmarti
Copy link
Contributor

@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.

@patrick-mota
Copy link

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.

@SoftwareApe
Copy link

SoftwareApe commented Jun 7, 2019

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".

@chrmarti
Copy link
Contributor

chrmarti commented Jun 7, 2019

We now read the home folder from /etc/passwd. (Available in 0.60.0, which currently requires VS Code Insiders to install.)

@MojoJojo86
Copy link

MojoJojo86 commented Jun 15, 2019

@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. :(

@chrmarti
Copy link
Contributor

@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.

@SoftwareApe
Copy link

@MojoJojo86 thank you, the home folder trick works on stable!

@MojoJojo86
Copy link

@chrmarti Cheers I tried the insiders edition and that worked.

@chrmarti chrmarti added plan-item A plan item and removed feature-request Request for new features or functionality labels Jun 24, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
containers Issue in vscode-remote containers plan-item A plan item
Projects
None yet
Development

No branches or pull requests

10 participants