Feature: Support docker-from-docker for dev containers with non-root user
See original GitHub issueIf you configure a container to use a non-root user, then attempting to build a docker image inside the dev container (i.e. by mounting the host’s /var/run/docker.sock
in the container), gives a permission denied error running docker build
. Using sudo docker build
results in a docker not found
error because the docker
CLI was installed as the non-root user.
It would be good to look at how to make this scenario work with the action/task.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top Results From Across the Web
Run the Docker daemon as a non-root user (Rootless mode)
Rootless mode allows running the Docker daemon and containers as a non-root user to mitigate potential vulnerabilities in the daemon and the container...
Read more >Add non-root user to a container - Visual Studio Code
Add a non-root user to a container ... Many Docker images use root as the default user, but there are cases where you...
Read more >Add default non-root user to all dev containers #108 - GitHub
To work around this issue, each dev container Dockerfile should provide a default non-root user with a argument based UID/GID and add comments ......
Read more >Processes In Containers Should Not Run As Root - Medium
Processes in a container should not run as root, or assume that they are root. Instead, create a user in your Dockerfile with...
Read more >(Optional) Running Docker images as a non-root user
Docker images run with root privileges by default. You can change this default setting to ensure that root access is denied to the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Proposal
This broadly follows the idea above and makes the steps a bit more explicit. It also adds some checks to error and fail in the conditions from the notes. My hope is that the error conditions will be fairly unlikely to be encountered and that this approach will be successful. Checking for these cases and erroring seems like a safe approach and can be revisited to look at alternative options if it ends up blocking usage.
Align user UID/GID
/etc/passwd
on the host to get the host user’s UID/GID/etc/passwd
in the container to get the container user’s UID/GIDUID
andGID
match then no further action needed/etc/passwd
in the container to see if the host user’s UID exists. If it does then error as there is a different user with that ID/etc/group
in the container to see if the host user’s GID exists. If it does then error as there is a different group with that ID/etc/passwd
in the container to use the new UID/etc/passwd
and/etc/group
in the container to use the new GIDAlign docker group ID
/etc/group
on the host to get thedocker
group ID on the host/etc/group
in the container to get thedocker
group ID in the container/etc/group
in the container to see if the host group ID exists. If it does then error as there is a different group with that IDdocker
group doesn’t exist in the container then create with the host group IDdocker
group does exist in the container then update it to have the host group IDThis can be extended to check the owning group for the docker socket rather than assuming that it is
docker
by runningstat -c '%G' /var/run/docker.sock
I think this would also make it possible to remove the
chown
‘workaround’ here which would be a nice benefit 😃