Low Orbit Flux Logo 2 D

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.

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

Build it:

sudo docker build -t myimage .

Run it:

sudo docker run --rm myimage id