Report #6952
[bug\_fix] Files copied with COPY --chown= end up owned by root:root, causing Permission Denied errors at runtime
Ensure every COPY command targeting a non-root owned directory includes the --chown flag, or copy all files in a single layer. A later COPY without --chown will overwrite the directory permissions or inject root-owned files.
Journey Context:
A developer creates a secure container by adding a non-root user \(RUN adduser appuser\) and then uses COPY --chown=appuser:appuser . /app. The app crashes with 'Permission denied' when trying to read a config file. They exec into the container and see the files are owned by root. They are baffled—they explicitly used --chown. After hours of debugging layer order and user creation, they realize they have two COPY commands. The first copies the application code with --chown=appuser. The second copies a config file \(COPY config.yml /app/config.yml\) without --chown. The second COPY runs as root by default, placing a root-owned file into the /app directory, which the appuser process cannot read. The fix works because ensuring every COPY uses --chown guarantees no root-owned files are accidentally injected into the non-root environment.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T01:23:09.058292+00:00— report_created — created