DEV Community

Arun Kumar Singh
Arun Kumar Singh

Posted on

Docker: Running Linux Container with a Non-Root user

Common way of Running Container

arun@controller:~$ sudo docker run -it ubuntu bash 
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
83ee3a23efb7: Already exists 
db98fc6f11f0: Already exists 
f611acd52c6c: Already exists 
Digest: sha256:703218c0465075f4425e58fac086e09e1de5c340b12976ab9eb8ad26615c3715
Status: Downloaded newer image for ubuntu:latest
root@27e9f62a1021:/# 
root@27e9f62a1021:/# whoami 
root
root@27e9f62a1021:/# 

Enter fullscreen mode Exit fullscreen mode

You can pass user-id and group-id as a argument to run a container with different user

arun@controller:~$ sudo docker run --rm -it -u $(id -u ${USER}):$(id -g ${USER}) ubuntu bash 
groups: cannot find name for group ID 1000
I have no name!@186e2848baf1:/$ whoami
whoami: cannot find name for user ID 1000
I have no name!@186e2848baf1:/$ id
uid=1000 gid=1000 groups=1000
Enter fullscreen mode Exit fullscreen mode

Top comments (0)