arrow_back
Back

Dockerfile USER: running processes as non-root

Andrew Dorokhov Andrew Dorokhov schedule 1 min read

USER sets the user (by name or UID) for all subsequent RUN, CMD, and ENTRYPOINT instructions.

UIDs are the same on the host and in the container, but usernames may map to different UIDs, which can complicate permission setup.

Example:

FROM centos:latest
RUN useradd -ms /bin/bash cloud_user
USER cloud_user

Always include USER in Dockerfiles (or switch users in ENTRYPOINT/CMD scripts). Without it, processes run as root, and a container compromise can grant root on the host.

code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

Dockerfile RUN: executing commands during build

arrow_forward