Django Dockerfile Generator: Complete Guide
Django Production Dockerfile Best Practices
Django requires running collectstatic at build time to gather all static assets into STATIC_ROOT. Set the DJANGO_SETTINGS_MODULE environment variable and use '--noinput' to avoid interactive prompts during the Docker build.
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
ENV DJANGO_SETTINGS_MODULE=myproject.settings
RUN python manage.py collectstatic --noinput
EXPOSE 8000
CMD ["gunicorn", "myproject.wsgi:application", "--bind", "0.0.0.0:8000"]