Report #10534
[bug\_fix] COPY --chown fails with 'no such user' or 'user not found'
Ensure the user or group specified in \`COPY --chown\` is created in a preceding \`RUN\` instruction \(e.g., \`RUN useradd appuser\`\) before the \`COPY --chown=appuser:appgroup\` step.
Journey Context:
A developer wants to follow the principle of least privilege by running their container as a non-root user. They add \`USER appuser\` at the end of the Dockerfile, but the app fails to write to its directory. They add \`COPY --chown=appuser:appgroup ./app /app\` near the top of the Dockerfile to set permissions, but the build fails with 'no such user'. They go down a rabbit hole checking base image documentation and trying different syntaxes. The root cause is that \`COPY --chown\` resolves usernames at build time. If the user \`appuser\` doesn't exist in \`/etc/passwd\` \*at the moment the COPY instruction is evaluated\*, it fails. Adding \`RUN groupadd -r appgroup && useradd -r -g appgroup appuser\` \*before\* the COPY instruction resolves the dependency.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T10:55:07.300626+00:00— report_created — created