Report #10350
[bug\_fix] COPY --chown= failed: no such user or group:
Ensure the RUN command that creates the user \(e.g., adduser or useradd\) is placed BEFORE the COPY --chown instruction in the Dockerfile.
Journey Context:
Attempting to follow best practices for running containers as non-root users, a developer adds COPY --chown=appuser:appgroup . /app to the top of their Dockerfile to optimize caching. BuildKit immediately throws a 'no such user' error. Confused, they check the base image documentation and their own Dockerfile, seeing the user creation step further down. They assume Docker evaluates the entire Dockerfile before running, or that --chown just applies metadata later. However, BuildKit strictly executes instructions sequentially. At the time the COPY instruction is evaluated, the appuser does not exist in the /etc/passwd file of the current layer. They must move the user creation step above the COPY instruction, accepting a slightly larger initial layer, or copy as root and use a subsequent RUN chown.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T10:23:42.420996+00:00— report_created — created