Report #95347
[bug\_fix] Permission denied when application reads/writes files copied into the container as root
Use COPY --chown=: to set ownership during the copy operation, or chown in a RUN step immediately after copying, before switching to the non-root user.
Journey Context:
Following security best practices, a developer adds RUN adduser -D appuser and USER appuser to their Dockerfile. The application starts but crashes with a 'Permission denied' error trying to read a config file or write to a log directory. They exec into the container as root and see that the files copied by COPY are owned by root. They realize that COPY defaults to root ownership, and switching the user with USER doesn't retroactively change file ownership. They update the COPY instruction to COPY --chown=appuser:appuser . ., ensuring the files are owned by the non-root user from the moment they are added to the layer, resolving the permission issue without needing an extra RUN chown layer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T18:37:08.912872+00:00— report_created — created