From e1fd61561ee0ec3dae52ee8e0adc5aa439c76812 Mon Sep 17 00:00:00 2001 From: Django Template Date: Thu, 11 Sep 2025 16:22:16 +0530 Subject: [PATCH] Fix Docker static files permissions for production deployment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Issue Fixed: - Static files collection failing with permission error in Docker container - Error: `PermissionError: [Errno 13] Permission denied: '/app/staticfiles/js'` - Occurs when running `python manage.py collectstatic` in production ## Solution Applied: 1. **Enhanced Dockerfile**: - Create `/app/staticfiles` and `/app/media` directories explicitly - Set proper ownership with `chown -R django:django /app` - Ensures directories exist with correct permissions before user switch 2. **Improved entrypoint.sh**: - Added `mkdir -p` to ensure directories exist at runtime - Creates directories before attempting static files collection - Provides fallback if directories weren't created in Docker build 3. **Updated Documentation**: - Added troubleshooting section for static files permission error - Explains the fix and prevention methods ## Benefits: - ✅ Resolves Docker container permission issues - ✅ Works with non-root user (security best practice) - ✅ Handles both build-time and runtime directory creation - ✅ Maintains proper file ownership for Django operations This should resolve the collectstatic permission error in Dokploy deployment. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- DOKPLOY.md | 8 ++++++++ Dockerfile | 5 ++++- entrypoint.sh | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/DOKPLOY.md b/DOKPLOY.md index d62e3f3..4b958db 100644 --- a/DOKPLOY.md +++ b/DOKPLOY.md @@ -250,6 +250,14 @@ If you see error: `FileNotFoundError: [Errno 2] No such file or directory: '/var **Solution**: This is already fixed in the latest version. The production settings now use console logging only, which is Docker-friendly and works with Dokploy's log viewing system. +### **Static Files Permission Error** +If you see error: `PermissionError: [Errno 13] Permission denied: '/app/staticfiles/js'` + +**Solution**: This is fixed in the latest version by: +- Creating static directories with proper permissions in Dockerfile +- Ensuring directories exist before collecting static files in entrypoint.sh +- Using proper Docker user permissions for file operations + ### **Domain Not Accessible** ```bash # Check DNS propagation diff --git a/Dockerfile b/Dockerfile index 14acd6f..7a6adbd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,7 +39,10 @@ RUN groupadd -r django && useradd -r -g django django COPY . /app/ -RUN chown -R django:django /app +# Create directories that need write permissions +RUN mkdir -p /app/staticfiles /app/media && \ + chown -R django:django /app + USER django EXPOSE 8000 diff --git a/entrypoint.sh b/entrypoint.sh index 12c75b7..a58ed26 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -15,6 +15,8 @@ echo "Setting up social applications..." python manage.py setup_social_apps echo "Collecting static files..." +# Ensure static directories exist with proper permissions +mkdir -p /app/staticfiles /app/media python manage.py collectstatic --noinput exec "$@" \ No newline at end of file