From f6d5d18f0d3a4dfc73352dc860ef3a1ea224b760 Mon Sep 17 00:00:00 2001 From: Bernard Siebens Date: Thu, 6 Aug 2026 21:58:09 +0200 Subject: [PATCH] Fix media volume permissions for non-root container user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /app/media didn't exist in the image, so the media_data volume had nothing to copy ownership from on first mount — Docker created the mount point owned by root, and the container runs as rosterchief. Uploads then failed with PermissionError. Create the directory before the chown so it carries the right ownership into the volume. --- Dockerfile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 86771e5..0c6d40b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -77,7 +77,13 @@ RUN DJANGO_SECRET_KEY=build-only-not-a-secret \ DJANGO_STATICFILES_BACKEND=whitenoise.storage.CompressedManifestStaticFilesStorage \ python manage.py collectstatic --noinput -RUN useradd --system --uid 1000 rosterchief && chown -R rosterchief /app +# mkdir before chown, and before the volume ever mounts: media_data has nothing to copy from +# at /app/media otherwise, so Docker creates the mount point itself, owned by root — and the +# app runs as rosterchief, not root. Existing image content (even an empty, correctly-owned +# dir) is what a named volume copies its initial ownership from on first use. +RUN useradd --system --uid 1000 rosterchief \ + && mkdir -p /app/media \ + && chown -R rosterchief /app USER rosterchief EXPOSE 8000