What this thread does
Do first: declare USER 1001:1001 in the final stage and inventory every file the startup command reads or writes before removing build tools.
Short answer
As of November 2026, use Docker current docs, November 2026. A UID/GID keeps the user consistently identified even if the container’s /etc/passwd file changes. Jay Schmidt’s USER article (June 26, 2024) explains ownership pitfalls.
Choose / don't choose
- Multi-stage: choose for a build toolchain that runtime does not need; copy the built executable plus its actual runtime dependencies, not the entire build filesystem (build guide).
- Distroless: choose when the required runtime exists in that image; do not choose a shell-dependent startup without rewriting it (image guide).
Not for: host bind-mount ownership; see docker-bind-mount-permission-denied-or-root-owned-files-on-host.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
USER | 1001:1001 is the documented example identity; provision matching writable paths | Linux final stage | USER article |
COPY --chown | 1001:1001 to match that identity; omitted flag creates UID/GID 0 files | Linux Dockerfile | reference |
COPY --from | build for a named build stage; retain executable, runtime dependencies and required assets | Multi-stage Dockerfile | build guide |
ENTRYPOINT | JSON array, e.g. ["/app/server"]; executable path is application-specific | Shell-free runtime | distroless |
STOPSIGNAL | Leave default stop behavior at SIGTERM unless application requires another signal | Docker container | stop reference |
Order of operations
1. Build dependencies and application in a named build stage. Check dynamic linkage/interpreter paths before selecting a runtime base; a copied binary is not necessarily self-contained. 2. Copy only required outputs. Create and assign each writable cache/data directory during image construction; when mounting volumes, Docker respects host-file UID and GID. Keep code read-only where practical (ownership guidance). 3. Set the final USER and direct entrypoint. In a disposable container, confirm effective UID is nonzero, exercise startup and actual writes, then send docker stop during a request and observe cleanup before the timeout (stop behavior).
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
| Non-vector ENTRYPOINT does not work | Container runtime prefixes ENTRYPOINT with a shell unless vector form is used | Use exec-form entrypoint and remove shell substitutions; add an appropriate runtime rather than silently copying a shell | distroless entrypoints |
| Runtime identity cannot write required files | Runtime identity does not have permission to read/write files in the mount | Give only the required directory the chosen UID/GID; do not restore root as a blanket fix | USER pitfalls |
sh entrypoint is present on production images? | The report discusses dash in the Python image | Inspect inherited ENTRYPOINT/CMD before diagnosing shell availability; kc-fiddler’s September 30, 2020 report discusses dash in the Python image | report |
Missing
- No application or base image is specified; exact artifacts, account database needs and writable directories require its startup contract. Image size and shutdown latency are workload measurements.
Checked
2026-11-12; Docker and distroless current docs, November 2026; Dockerfile, build/stop references, Schmidt article and kc-fiddler report read. No application commands were executed.
Started from a post by @Docker and distroless current docs, November 2026, packaged by the editor. Original post