Elena' s AI Blog

Docker Permissions Without Panic: Why I Ran chown Inside My Container

26 Jun 2026 (updated: 24 Aug 2026) / 36 minutes to read

Elena Daehnhardt


DALL-E via ChatGPT: a friendly blue whale carrying neatly labelled cargo containers, one worker handing a key to another at the dock


TL;DR:
  • - `Permission denied` inside a container is almost always an ownership mismatch: root created the folders, but the app runs as `appuser`.
  • - Linux matches permissions on the numeric UID/GID, not the name — so a bind-mounted folder owned by host UID 501 will not magically belong to the container's `appuser`.
  • - Fix it with `chown -R appuser:appuser` on the specific folders, never `chmod 777`, which simply switches the locks off.
  • - The permanent cure lives in your Docker setup: `COPY --chown`, a `RUN chown` for built folders, and an entrypoint that fixes volume ownership before dropping privileges with `gosu`.

📚 This post is part of the "MLOps & Deployment" series

Series: MLOps & Deployment (Part 2 of 9)

  • Part 2: Docker Permissions Without Panic: Why I Ran chown Inside My Container

Previous: Part 2 — Docker Permissions Without Panic: Why I Ran chown Inside My Container

Fixing Docker “Permission denied” for a Non-Root Container User

A Docker permission error is an ownership mismatch: a folder created by root (at image build or container startup) is being written to by an application that runs as a non-root user such as appuser, so Linux refuses the write. The fix is to change folder ownership with chown, not to loosen permissions with chmod 777.

Sometimes Docker does not fail loudly.

It does not say:

Hello Elena, your container is fine, but your app cannot write to the folder because the owner is wrong.

No. Docker prefers mystery.

You run the app. Everything looks healthy. The container is up. Nginx is serving. Flask is alive. Then suddenly uploads fail, backups do not appear, static files refuse to update, or Python throws one of those wonderfully unhelpful messages:

Permission denied

In my case, the fix was this command:

docker compose exec -u root web chown -R appuser:appuser /backups /app/protected_files /app/app/static

At first glance, it looks like a scary Linux spell.

But it is actually a very practical Docker permissions repair.

Let’s unpack it.

The Proper Fix: Own It at Build, Repair Volumes at Runtime

🔒 Subscribe to keep reading.

Subscribe to unlock the full article ❤️

I keep most of the site completely open. A few unusually detailed tutorials need a free subscriber login so I can keep publishing this kind of work.

The form below signs you up for the newsletter. It does not log you into the app — log in afterwards (same email) to unlock this article and download your subscriber gifts. New subscribers get an inbox mail: Set a password to unlock articles.

desktop bg dark

About Elena

Elena, a PhD in Computer Science, simplifies AI concepts and helps you use machine learning.





Citation
Elena Daehnhardt. (2026) 'Docker Permissions Without Panic: Why I Ran chown Inside My Container', daehnhardt.com, 26 June 2026. Available at: https://daehnhardt.com/blog/2026/06/26/docker-permissions-without-panic/
All Posts