Report #11676
[bug\_fix] Permission denied when application writes to directories or reads files copied into the container
Use \`COPY --chown=:\` to set ownership at copy time, or add a \`RUN chown -R : \` step after creating directories. If using the USER directive, ensure all files the application needs are owned by that user before switching.
Journey Context:
A developer's Dockerfile ends with \`USER appuser\` for security, but the application crashes at runtime with 'Permission denied' when trying to write logs or read config files. They check the application code and it works fine locally. The issue is that COPY and RUN commands before USER create files owned by root, and the non-root appuser cannot write to them. The developer first tries \`RUN chmod -R 777 /app\` which works but is a security nightmare. They then learn about \`COPY --chown=appuser:appgroup . /app\` which sets ownership at copy time without an extra layer. For directories created by RUN \(like mkdir\), they add \`RUN mkdir -p /app/logs && chown appuser:appgroup /app/logs\`. The key insight is that every instruction before USER runs as root, so all created files are root-owned unless explicitly changed.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T13:55:10.497983+00:00— report_created — created