DELAPARRA
Index
Color
NL
Category: Docker

USER

Explained by Updated

What is USER?

USER: Sets the user (and optionally group) that RUN, CMD, and ENTRYPOINT run as. Use it to avoid running as root. USER in a Dockerfile sets which user the following RUN steps, and the container's main process, run as. USER app switches from root to a normal user named app. By default, containers run as root. If an attacker finds a hole in your application, they then have root rights inside the container, which makes escaping to the host or abusing mounted files much easier.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about USER

What should you keep in mind with USER?

Create a dedicated user in the image, give it ownership of only the folders it needs to write, such as storage and cache, and switch to it before the final command. Many official images already include a suitable user, like node or www-data. Kubernetes can enforce this with runAsNonRoot: true in the security context, which refuses to start containers that would run as root.

What does an example of USER look like?

RUN adduser -D app USER app

At a glance

CategoryDocker
Explained by
Updated

More Docker terms

All terms starting with U

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.