2

I am trying to use the devcontainers feature of VS Code. However, ownership of the files in my work directory keep getting changed to root even though I set the permissions in the image. As a result I get "permission denied" errors whenever I try to edit my files.

Here are the dockerfile and devcontainer.json file that I am using.

FROM rocker/r-ver:4.2.1


ARG USERNAME=user
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# create non-root user
# Create the user
RUN groupadd --gid $USER_GID $USERNAME \
    && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME --shell /bin/bash \
    #
    # [Optional] Add sudo support. Omit if you don't need to install software after connecting.
    && apt-get update \
    && apt-get install -y sudo \
    && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
    && chmod 0440 /etc/sudoers.d/$USERNAME

ENV PATH "${PATH}:/home/user/.local/bin"
RUN echo "export PATH=${PATH} >> /home/user/.bashrc"

RUN mkdir -p /home/user/workspace && \
    chown $USERNAME:$USER_UID /home/user/workspace
WORKDIR /home/user/workspace

USER $USERNAME

and my devcontainer.json is

{
    "name":"R Development Environment",
    "build": {
        "dockerfile":"Dockerfile-r",
        "context":"..",
        "args": {"R_VERSION":"4.1.2"}
    },

    "settings": {
        "r.rterm.linux": "/usr/local/bin/radian",
        "r.bracketedPaste": true,
        "r.plot.useHttpgd": true,
        "[r]": {
            "editor.wordSeparators": "`~!@#%$^&*()-=+[{]}\\|;:'\",<>/?"
        }
    },
    "workspaceFolder":"/home/user/workspace",
    "workspaceMount": "source=${localWorkspaceFolder},target=/home/user/workspace,type=bind,consistency=cached",


    "extensions": [
        "REditorSupport.r",
        "rdebugger.r-debugger"
    ],
    "remoteUser": "user"
}
thewayup
  • 1,155
  • 1
  • 9
  • 11

0 Answers0