This is an AMP version of the article, its original content can be found here.

How We Run as a Non-Root Inside Docker Container

Docker starts a process inside its container as a "root" user. In some cases, this is not convenient though. For example, initdb from PostgreSQL doesn't like to be started as root and will fail. In, a DevOps team assistant, we're using Docker as a virtualization technology for every build we run.

Here is how we change the user inside a running container, right after it is started.

First, this is how we start a new Docker container:

There are two files in the current directory: and is the file being executed by Docker on start, and it contains the following: will be executed as a user r inside the container. And this r user will have sudo permissions. This is exactly what all projects, managing their DevOps procedures with, need.