mirror of
https://github.com/thecyberlearn/modern-django-starter.git
synced 2026-08-18 08:52:55 +00:00
## Problem Analysis: - Static files collection failing with permission errors in Docker containers - Non-root user cannot create directories in container filesystem - Previous fix didn't handle runtime permission management properly ## Comprehensive Solution: ### 1. Enhanced Dockerfile: - Added `gosu` package for secure user switching - Removed premature USER directive - run setup as root first - Improved directory permissions with proper chmod/chown ### 2. Robust Entrypoint Script: - Runs initial setup (migrations, static collection) as root - Explicitly sets directory permissions for static/media files - Uses `gosu` to securely switch to django user for main application - Ensures proper ownership before application starts ### 3. Updated Docker Compose Volume: - Changed volume mapping to use ../files/staticfiles (more descriptive) - Ensures persistent storage for static files across deployments ## Security & Best Practices: - ✅ Maintains security with non-root application runtime - ✅ Handles setup operations with necessary root permissions - ✅ Uses gosu for secure user switching (better than su/sudo) - ✅ Explicit permission management for container directories ## Benefits: - Resolves all static files permission errors - Works reliably in containerized environments - Maintains security best practices - Compatible with Dokploy and other orchestration platforms This should completely resolve the collectstatic permission issues. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
51 lines
1.3 KiB
YAML
51 lines
1.3 KiB
YAML
services:
|
|
web:
|
|
build:
|
|
context: .
|
|
target: production
|
|
command: >
|
|
sh -c "chmod +x /app/entrypoint.sh &&
|
|
/app/entrypoint.sh &&
|
|
gunicorn --bind 0.0.0.0:8000 --workers 3 django_project.wsgi:application"
|
|
volumes:
|
|
- "../files/staticfiles:/app/staticfiles"
|
|
- "../files/media:/app/media"
|
|
expose:
|
|
- 8000
|
|
env_file:
|
|
- .env
|
|
depends_on:
|
|
- db
|
|
- redis
|
|
environment:
|
|
- DJANGO_SETTINGS_MODULE=django_project.settings.production
|
|
networks:
|
|
- dokploy-network
|
|
labels:
|
|
- "traefik.enable=true"
|
|
- "traefik.http.routers.django-app.rule=Host(`your-domain.com`)"
|
|
- "traefik.http.routers.django-app.entrypoints=websecure"
|
|
- "traefik.http.routers.django-app.tls.certResolver=letsencrypt"
|
|
- "traefik.http.services.django-app.loadbalancer.server.port=8000"
|
|
|
|
db:
|
|
image: postgres:15-alpine
|
|
volumes:
|
|
- "../files/postgres_data:/var/lib/postgresql/data/"
|
|
environment:
|
|
- POSTGRES_DB=${DB_NAME:-django_db}
|
|
- POSTGRES_USER=${DB_USER:-django_user}
|
|
- POSTGRES_PASSWORD=${DB_PASSWORD:-django_password}
|
|
networks:
|
|
- dokploy-network
|
|
|
|
redis:
|
|
image: redis:7-alpine
|
|
volumes:
|
|
- "../files/redis_data:/data"
|
|
networks:
|
|
- dokploy-network
|
|
|
|
networks:
|
|
dokploy-network:
|
|
external: true |