I have a workflow as follows for publishing webapps to my dev server. The server has a single docker host and I\'m using docker-compose for managing containers.
Please take a look at this docker file I just posted: https://github.com/bdruemen/jenkins-docker-uid-from-volume/blob/master/gid-from-volume/Dockerfile
Here the GID extracted from a mounted volume (host directory), with
stat -c '%g'
Then the GID of the group of the container user is changed to the same value with
groupmod -g
This has to be done as root, but then root privileges are dropped with
gosu
Everything is done in the ENTRYPOINT, so the real GID is unknown until you run
docker run -d -v : ...
Note that after changing the GID, there might be other files in the container no longer accessible for the process, so you might need a
chgrp -R
before the gosu command.
You can also change the UID, see my answer here Changing the user's uid in a pre-build docker container (jenkins) and maybe you want to change both to increase security.