Docker USER and --user - run containers as a non-root UID
Answer: The USER instruction picks a user name or UID, and optionally a group or GID, as the default for later steps in this stage. At runtime, docker run --user sets the username or UID used, and optionally the groupname or GID.
Examples
FROM python:3.13-slim
RUN useradd --create-home --uid 10001 appuser
USER appuser
WORKDIR /app
COPY --chown=appuser:appuser . .
CMD ["python", "app.py"]
docker run --user 10001:10001 myapp
docker run --user appuser myapp
Rules
- When you specify a group, the user will have only the specified group membership.
- The specified user is used for RUN instructions and at runtime for ENTRYPOINT and CMD.
- If you pass a numeric user ID, it must be in the range of valid UIDs.
See also
Claims
- id: C1 claim: USER sets the default user name or UID. source: S1 evidence: "The USER instruction sets the user name (or UID) and optionally the user group"
- id: C2 claim: A specified group is the user's only membership. source: S1 evidence: "the user will have only the specified group membership"
- id: C3 claim: --user sets a username or UID and optional group. source: S2 evidence: "Sets the username or UID used and optionally the groupname or GID"
Sources
- [S1] Dockerfile reference. Docker docs. https://docs.docker.com/reference/dockerfile/ . License: Apache-2.0. Accessed 2026-11-18.
- [S2] Running containers. Docker docs. https://docs.docker.com/engine/reference/run/ . License: Apache-2.0. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Docker docs, Dockerfile reference; Docker docs, Running containers. Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Docker docs, Dockerfile reference; Docker docs, Running containers. Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc.
Cite this
iinventedlight. 2026. "Docker USER and --user - run containers as a non-root UID." iinventedlight Library, iil:note:zed2q82r, version of 2026-11-18. https://iinventedlight.com/library/notes/docker-user/. License: CC-BY-4.0.
@misc{iil_note_zed2q82r,
author = {{iinventedlight}},
title = {{Docker USER and --user - run containers as a non-root UID}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/docker-user/},
note = {Permanent ID iil:note:zed2q82r. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/docker-user.md.