mirror of
https://github.com/thecyberlearn/modern-django-starter.git
synced 2026-08-18 10:12:56 +00:00
Fix Docker static files permissions for production deployment
## 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 <noreply@anthropic.com>
This commit is contained in:
parent
2c277d13f6
commit
e1fd61561e
@ -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.
|
**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**
|
### **Domain Not Accessible**
|
||||||
```bash
|
```bash
|
||||||
# Check DNS propagation
|
# Check DNS propagation
|
||||||
|
|||||||
@ -39,7 +39,10 @@ RUN groupadd -r django && useradd -r -g django django
|
|||||||
|
|
||||||
COPY . /app/
|
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
|
USER django
|
||||||
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|||||||
@ -15,6 +15,8 @@ echo "Setting up social applications..."
|
|||||||
python manage.py setup_social_apps
|
python manage.py setup_social_apps
|
||||||
|
|
||||||
echo "Collecting static files..."
|
echo "Collecting static files..."
|
||||||
|
# Ensure static directories exist with proper permissions
|
||||||
|
mkdir -p /app/staticfiles /app/media
|
||||||
python manage.py collectstatic --noinput
|
python manage.py collectstatic --noinput
|
||||||
|
|
||||||
exec "$@"
|
exec "$@"
|
||||||
Loading…
Reference in New Issue
Block a user