USER

The Dockerfile instruction that sets which user later instructions and the container run as.

In more detail

Without it containers run as root. Create an unprivileged user in the image and switch to it with USER app (or a numeric UID such as 10001) near the end, after steps that need root. It is one of the cheapest and most effective hardening steps.

Examples

RUN adduser -D -u 10001 app
USER 10001
USER node before CMD in the runner stage
USER nonroot:nonroot
USER 10001

Related terms

Taught in

References

Certification courses