0

I want to create a devcontainer for a non root user, I want to set /workspace uid:gid to USER_UID and USER_GID, but it seems impossible.

I have created a dockerfile for a devcontainer image:

FROM debian:testing-slim

ARG USERNAME=myuser
ARG USER_UID=1000
ARG USER_GID=$USER_UID

RUN apt-get update \
&& apt-get install --no-install-recommends --assume-yes \
mingw-w64 \
git

RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME

USER $USERNAME

a named volume is mounted on /workspace as "workspaceFolder" in .devcontainer.json

{
    "name": "Debian MinGW w64",
    "image": "shockagent/debian-mingw-w64:latest",
    "shutdownAction": "stopContainer",
    "workspaceMount": "source=vscode-workspace,target=/workspace,type=volume",
    "workspaceFolder": "/workspace"
}

from this point on I am stuck: I have tried to RUN mkdir /workspace && chown -R 1000:000 /workspace in dockerfile, I have also tried to set volume-opt=uid=1000,volume-opt=gid=1000 in workspaceMount, but nothing happened.

I see that "workspaceMount" Overrides the default local mount point for the workspace when the container is created, so i thought I would issue the chown command in devcontainer.json, but none of the following callbacks worked: onCreateCommand, postCreateCommand, postStartCommand.

For example, "postStartCommand": "whoami && chown -R 1000:1000 /workspace"

Running the postStartCommand from devcontainer.json...

[6046 ms] Start: Run in container: /bin/sh -c whoami && chown -R 1000:1000 /workspace
myuser
chown: changing ownership of '/workspace': Operation not permitted

The problem is that command are issued as myuser and not as root.

How can I create a devcontainer for a non root user and set ownership/permissions of the /workspace directory ?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • Have you tried setting myuser with sudo permissions then running sudo chown? – Rich Tebb Jun 20 '23 at 08:45
  • Adding this command worked though `RUN mkdir /workspace && chown -R 1000:000 /workspace` ( above `USER $USERNAME` ), was able to create dir inside /workspace/new-dir as myuser – Kaushik R Bangera Jul 27 '23 at 19:06

0 Answers0