Skip to content

Determine install folder from within the container #22

Closed

Description

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

Activity

  1. Chuxel commented on May 2, 2019

    @Chuxel
    Member

    Damian Pukaluk (@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?

  2. added
    containers
    info-needed
    on May 2, 2019
  3. javierdihu commented on May 2, 2019

    @javierdihu

    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.

  4. changed the title [-]Permission denied during attaching[/-] [+]Add option to override install directory[/+] on May 3, 2019
  5. added
    feature-request
    and removed
    info-needed
    on May 3, 2019
  6. threaz commented on May 3, 2019

    @threaz
    Author

    Thanks for your response Chuck Lantz (@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.

  7. changed the title [-]Add option to override install directory[/-] [+]Determine install folder from within the container[/+] on May 3, 2019
  8. chrmarti commented on May 3, 2019

    @chrmarti
    Contributor

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

  9. vijay609 commented on May 17, 2019

    @vijay609

    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.
  10. costela commented on May 17, 2019

    @costela

    Javier Diaz (@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.

  11. nickolai-voyage commented on May 17, 2019

    @nickolai-voyage

    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.

  12. nickolai-voyage commented on May 20, 2019

    @nickolai-voyage

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

  13. costela commented on May 21, 2019

    @costela

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

  14. chrmarti commented on May 21, 2019

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

  15. patrick-mota commented on May 22, 2019

    @patrick-mota

    Seems a good idea Christof Marti (@chrmarti) and doing what Leo Antunes (@costela) said resolved the problem.

    I just added
    HOME: /home/yourusername
    in environnment for the service where vscode remote will enter.

  16. SoftwareApe commented on Jun 7, 2019

    @SoftwareApe

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

  17. chrmarti commented on Jun 7, 2019

    @chrmarti
    Contributor

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

  18. MojoJojo86 commented on Jun 15, 2019

    @MojoJojo86

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

  19. chrmarti commented on Jun 17, 2019

    @chrmarti
    Contributor

    Joseph Bradshaw (@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.

  20. SoftwareApe commented on Jun 17, 2019

    @SoftwareApe

    Joseph Bradshaw (@MojoJojo86) thank you, the home folder trick works on stable!

  21. MojoJojo86 commented on Jun 17, 2019

    @MojoJojo86

    Christof Marti (@chrmarti) Cheers I tried the insiders edition and that worked.

  22. added
    plan-item
    and removed
    feature-request
    on Jun 24, 2019
  23. locked and limited conversation to collaborators on Jul 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

containersplan-item

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions