5

After reading some articles I'm still not sure about what user I should use to run a docker container. Are there any security concerns when running a docker container as root user? Is it ok to run docker containers as root user OR should I use my normal user, add him to the "docker" group and then run my containers OR should I create an additional user only for managing/creating docker containers?

root@myDockerHost:/opt/myDockerContainer# docker-compose up -d

VS

chris@myDockerHost:/opt/myDockerContainer# docker-compose up -d

VS

dockerusr@myDockerHost:/opt/myDockerContainer# docker-compose up -d

(I'm talking about the users on my docker host - not the user inside a container!)

2

r00tusr!

I vote for always running containers as regular users.

In a production system your containers won't be run as root. Even in non-production systems, the users who run your container might not be allowed to run programs as root.

So I like to make them work properly as an unprivileged user, even when it's difficult.

Also, there's the security consideration. The general rule professional sysadmins follow is never to run something as root unless it really, really must. Once a program is running as root, it has full control of the computer and can do anything to that computer that it is told to do. Whether that be the good works the author intended or nefarious works by a neer-do-well who cracks into the author's program through a vulnerability that author didn't think to close.

Since we've finally learned that we really, truly cannot predict which programs have flaws, we just don't take chances anymore.

Thanks! Mike

1

It makes little difference. The docker-compose command connects to the docker.sock, aka docker's API, to run all container commands. By default, this API is only accessible to the root user on linux, so you often see people running commands with sudo.

You can configure docker to allow non-root users to access this API, just be sure you trust these users with root access on your host, since the API gives that level of access. See this answer for details on how to give users this access. The dockerd daemon is typically configured to run as root, the user accessing this API makes little difference (there is rootless mode currently in experimental).

The important detail is to run applications inside of your container as a non-root user. It's the equivalent of systemd running as root and launching a program as a non-root user. You configure this user in the Dockerfile, docker-compose.yml, or your docker run -u CLI.

The reason I say "little difference" is that a compose file can configure host mounts that have a relative path. If you run docker-compose command as root or a different user, those host mounts may be a different path, and the files may be owned by a different UID, that may or may not map to the UID of your application inside the container. Beyond that, I can't think of any difference between running docker-compose as a user or root.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.