Skip to content

Latest commit

 

History

History
31 lines (23 loc) · 1.53 KB

Running-Containers-as-ROOT.md

File metadata and controls

31 lines (23 loc) · 1.53 KB

Running Docker Containers as ROOT:

One of the best practices while running Docker Container is to run processes with a non-root user. This is because if a user manages to break out of the application running as root in the container, he may gain root user access on host. In addition, configuring container to user unprivileged is the best way yo prevent privilege escalation attacks.

This can be accomplished in different ways:

  • USER instruction in Dockerfile.

Example:

FROM alpine
RUN groupadd -r myuser && useradd -r -g myuser myuser
"HERE DO WHAT YOU HAVE TO DO AS A ROOT USER LIKE INSTALLING PACKAGES ETC."
USER myuser
  • Using -u flag during runtime This option can be used if the image doesn't have its own user. Example:
docker run --user 1001 alpine

Other References: