Skip to content

Conversation

alexander-smolyakov
Copy link
Contributor

Dev container name:

  • miniconda

Description:
This PR removes the USER instruction from the devcontainer Dockerfile. According to Docker documentation, when we set the user in the Dockerfile. The specified user is used for RUN instructions and, at runtime, runs the relevant ENTRYPOINT and CMD commands. This caused the issue with the miniconda template.

We copy several files to the container in the related template and remove them afterward:

# Copy environment.yml (if found) to a temp location so we update the environment. Also
# copy "noop.txt" so the COPY instruction does not fail if no environment.yml exists.
COPY environment.yml* .devcontainer/noop.txt /tmp/conda-tmp/
RUN if [ -f "/tmp/conda-tmp/environment.yml" ]; then umask 0002 && /opt/conda/bin/conda env update -n base -f /tmp/conda-tmp/environment.yml; fi \
    && rm -rf /tmp/conda-tmp

When Docker attempts to remove the conda-tmp folder, the following error appears:

> [dev_container_auto_added_stage_label 3/3] RUN if [ -f "/tmp/conda-tmp/environment.yml" ]; then umask 0002 && /opt/conda/bin/conda env update -n base -f /tmp/conda-tmp/environment.yml; fi     && rm -rf /tmp/conda-tmp:
#0 0.343 rm: cannot remove '/tmp/conda-tmp/noop.txt': Permission denied
------
[2023-05-09T15:58:53.496Z] Dockerfile-with-features:8
[2023-05-09T15:58:53.508Z] 
--------------------
   7 |     COPY environment.yml* .devcontainer/noop.txt /tmp/conda-tmp/
   8 | >>> RUN if [ -f "/tmp/conda-tmp/environment.yml" ]; then umask 0002 && /opt/conda/bin/conda env update -n base -f /tmp/conda-tmp/environment.yml; fi \
   9 | >>>     && rm -rf /tmp/conda-tmp
  10 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c if [ -f \"/tmp/conda-tmp/environment.yml\" ]; then umask 0002 && /opt/conda/bin/conda env update -n base -f /tmp/conda-tmp/environment.yml; fi     && rm -rf /tmp/conda-tmp" did not complete successfully: exit code: 1

The issue is related to the fact that the RUN instruction runs via the vscode user (Due to the USER instruction) while only the root user has the write permissions for the /tmp/conda-tmp folder.

vscode ➜ ~ $ tree -up  /tmp/
/tmp/
├── [drwxr-xr-x root    ]  conda-tmp
│   └── [-rwxr-xr-x root    ]  noop.txt

Changelog:

  • Removed the USER instruction form Dockerfile to ensure that all subsequent commands run via the root user.

Attached related issue:

Checklist:

  • Checked that applied changes work as expected

- Remove `USER` instruction to make sure that all subsequent commands running form the root user
@alexander-smolyakov alexander-smolyakov requested a review from a team as a code owner May 11, 2023 14:27
Copy link
Member

@samruddhikhandale samruddhikhandale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@samruddhikhandale samruddhikhandale merged commit 8fb5d26 into devcontainers:main May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants