Report #35191
[bug\_fix] COPY --chown=: fails with 'no such user or group' during the Docker build
Create the user and group in a preceding \`RUN\` instruction \(e.g., \`RUN addgroup -S appgroup && adduser -S appuser -G appgroup\`\) before using them in the \`COPY --chown\` instruction.
Journey Context:
A developer wants to follow the principle of least privilege and adds \`COPY --chown=appuser:appgroup . /app\` to their Dockerfile, followed by \`USER appuser\`. The build immediately fails with 'no such user'. They are confused because they specified \`USER appuser\` right after. They dig into BuildKit permissions handling, thinking it's a chown parsing error. They realize that \`COPY --chown\` resolves the UID/GID against the image's \`/etc/passwd\` and \`/etc/group\` \*at the moment the instruction is executed\*. Since the base image doesn't contain \`appuser\`, the chown fails. The user must be created in a prior \`RUN\` step before it can be referenced by name in \`COPY --chown\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T13:32:49.762714+00:00— report_created — created