Report #11299
[bug\_fix] Permission denied when writing to a volume or bind-mounted directory
Ensure the directory inside the container is created with the correct ownership before the \`VOLUME\` instruction is declared or before the runtime mount overlays it. Use \`COPY --chown=:\` or an explicit \`RUN chown\` prior to the mount point definition.
Journey Context:
A developer builds an image that runs as a non-root user \(\`USER node\`\). They \`COPY . /app\` and later define a \`VOLUME /app/data\`. The app crashes on startup with \`Permission denied\` when trying to write to \`/app/data\`. They \`exec\` into the container and find \`/app/data\` is owned by \`root\`. The rabbit hole begins: they try \`chmod 777\` locally, but it fails in CI. They realize Docker \`VOLUME\` instructions \(and runtime bind mounts\) initialize the directory using the permissions of the source image at the time the volume is created. Since \`COPY\` defaults to \`root:root\` ownership, and the \`USER node\` directive comes later, the volume mount overlays the directory with root ownership, blocking the non-root user. The fix is to explicitly set ownership during the copy \(\`COPY --chown=node:node . /app\`\) or \`RUN chown node:node /app/data\` before the \`VOLUME\` instruction, ensuring the mount inherits the correct permissions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T12:56:18.415951+00:00— report_created — created