Docker replicates UID / GID in container from host

When creating Docker containers, I constantly encounter the problem that the UID / GID is not reflected in the container (I understand that this is by design). What I'm looking for is a way to intelligently resolve the host and / or replicate UID / GID from the host user / group accounts in my Docker container. For instance:

host -

woot4moo: x: 504: 504: woot4moo: / home / woot4moo: / bin / bash

I would like this to be the same behavior in a Docker container. That being said, is this even the right way to do this? I am convinced that I can simply run:

useradd -u 504 -g 504 woot4moo 

as part of my Docker file, but I'm not sure if it really is.

+5
source share
1 answer

You would not want to run this as part of the image building process (in your Docker file), because the host on which someone runs the container is often not the host on which you create the image.

One way to solve this is to pass UID / GID information through environment variables:

 docker run -e APP_UID=100 -e APP_GID=100 ... 

And then before the CMD :

enter an ENTRYPOINT script that includes something like the following:
 useradd -c 'container user' -u $APP_UID -g $APP_GID appuser chown -R $APP_UID:$APP_GID /app/data 
+5
source

All Articles