Docker How To Not Run As Root
It is possible to not run as root with Docker. There are a few different things that you might want to do.
- Run the Docker client without root access
- Define an image that runs as non-root
- Run the Docker daemon as non-root
We are going to show you how to do the first two of those things. For the third, check out this documentation HERE.
Run the Docker client without root access:
Add your user to the docker group:
sudo usermod -aG docker user1
The docker group should already exist but if it doesn’t you can add it like this:
sudo groupadd docker
Defining an image that runs as non-root
Create a Dockerfile for an image that will run as a user named “user1”:
FROM ubuntu RUN useradd -u 1000 user1 USER user1
sudo docker build -t myimage .
sudo docker run --rm myimage id