Docker Community Forums

Share and learn in the Docker community.

Question about the USER in docker container


(Shi Ai) #1

I met a problem while useing docker.
Now I have a ubuntu based docker container. And in the container ,the user id is root by default which is not my expectation, I suppose the user id is like “abc” which is another user account on the HOST OS running docker.
I have tried the following ways but all fail:
(1) su abc; then running docker run xxx to bring up a container, but login the container, the user in container is still root.
(2) by adding the “-u” flag for docker run: like : docker run -t -i -u abc ubuntu /bin/bash, the the docker show errors "unable to find user abc"
Can some one tell me how to fix it?
Or does docker support run a container in which the user is a specfic one than the default “root”?


(Nathan Le Claire) #2

Usually this is done with USER in Dockerfile.


(Jeff Anderson) #3

If you want to specify a user with the -u flag at runtime, or with the USER directive in the Dockerfile, the user must exist in the container. Your container won’t see that there’s a user on your host with that name.

It is typical to see an adduser or useradd command in a Dockerfile where the container will run as that user.