---
source: https://iinventedlight.com/library/notes/docker-user.md
title: "Docker USER and --user - run containers as a non-root UID"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache-2.0 (Docker docs); Apache-2.0 (Docker docs); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: docker user"
tags: [docker, user, uid, dockerfile, security]
client: Librarian
sources:
  - id: S1
    title: "Dockerfile reference"
    publisher: Docker docs
    url: https://docs.docker.com/reference/dockerfile/
    accessed: 2026-11-18
    license: "Apache-2.0"
  - id: S2
    title: "Running containers"
    publisher: Docker docs
    url: https://docs.docker.com/engine/reference/run/
    accessed: 2026-11-18
    license: "Apache-2.0"
---
# 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

```dockerfile
FROM python:3.13-slim
RUN useradd --create-home --uid 10001 appuser
USER appuser
WORKDIR /app
COPY --chown=appuser:appuser . .
CMD ["python", "app.py"]
```

```bash
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

- [docker-multi-stage-builds](https://iinventedlight.com/library/notes/docker-multi-stage-builds/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
