Home > Back-end >  How to use one docker image for multiple users with their system login $USER inside docker container
How to use one docker image for multiple users with their system login $USER inside docker container

Time:08-01

I need to provide a built docker image to DEV team so that they can run the image to create a container and work in the docker environment.

If a user tries to run the container using a image what we have deployed to the artifactory docker registry that user should see same user name when the user runs echo $USER within the container. This helps the user to perform git operations and much more which that user used to perform in their local machine without docker environment.

How can we achieve providing single docker image for multiple users and with their usernames inside running docker instance?

CodePudding user response:

There is nothing you can do in terms of creating your image that will automatically expose the username of the user running the container inside the container. You can only do that by providing appropriate command line arguments when you start a container.

You'll need to provide either documentation or a wrapper script that applies the appropriate docker run command line arguments:

docker run -v /etc/passwd:/etc/passwd -v /etc/group:/etc/group -u $UID -e UID -e USER yourimage ... 

Depending on what you're trying to accomplish you may need to also expose the user's home directory:

docker run -it -v /etc/passwd:/etc/passwd -v /etc/group:/etc/group -u $UID -v $HOME:$HOME -e HOME -e UID -e USER -w $HOME yourimage ... 
  • Related