Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind mount docker with specific user and permission [closed]

Scenario I want to use Docker in Docker as per this guide

The key point is that you'll need to bind mount the Docker socket from host machine into the Docker socket inside the container in order to use Docker from inside the container.

Issue The Docker socket on the host machine is always bind mounted into Docker container under root:root. When I execute the container as a non-root user, executing Docker commands gives permission denied.

Question How to bind mount a file from host into Docker container with specific user:group and permission?

like image 992
Tran Triet Avatar asked Sep 17 '19 03:09

Tran Triet


People also ask

How do you give a non root user in Docker container access to a volume mounted on the host?

You need to run the appropriate chown and chmod commands to change the permissions of the directory. This assumes you have the runuser command available. You can accomplish pretty much the same thing using sudo instead.

How does Docker bind mount work?

Bind mounts will mount a file or directory on to your container from your host machine, which you can then reference via its absolute path. To use bind mounts, the file or directory does not need to exist on your Docker host already. If it doesn't exist, it will be created on demand.


Video Answer


1 Answers

I think you can workaround that:

set the group permission on the file to ID not exists on the host, and give the group full access:

chown :999 /path/to/file
chmod 775 /path/to/file
chmod g+s /path/to/file

then on your Dockerfile add the group and assign the user to it:

RUN addgroup --gid 999 GROUPNAME 
RUN adduser --disabled-password --gecos "" --force-badname --ingroup 999 USERNAME
like image 112
LinPy Avatar answered Oct 14 '22 19:10

LinPy