modern-django-starter/Dockerfile.simple
amitrana01 6185c25776 Add simplified Dokploy configuration based on working quantum-digital project
Based on analysis of successfully deployed project:
- Create docker-compose.dokploy-simple.yml with ports instead of expose
- Remove complex Traefik labels (let Dokploy handle routing via Domain UI)
- Hardcode environment variables in compose file
- Run migrations in the command directly
- Add Dockerfile.simple following their working multi-stage pattern
- Includes Tailwind build and health check

Use docker-compose.dokploy-simple.yml and configure domain via Dokploy UI
2025-09-11 18:29:18 +05:30

82 lines
2.2 KiB
Docker

# Multi-stage Dockerfile for Django production deployment
# Build stage
FROM python:3.11-slim as builder
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpq-dev \
curl \
&& curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
&& apt-get install -y nodejs \
&& rm -rf /var/lib/apt/lists/*
# Create and set work directory
WORKDIR /app
# Install Python dependencies
COPY requirements/production.txt ./requirements/
RUN pip install --no-cache-dir -r requirements/production.txt
# Production stage
FROM python:3.11-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
DJANGO_SETTINGS_MODULE=django_project.settings.production
# Install system dependencies for production
RUN apt-get update && apt-get install -y \
libpq5 \
curl \
&& curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
&& apt-get install -y nodejs \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN groupadd -r django && useradd -r -g django django
# Set work directory
WORKDIR /app
# Copy Python dependencies from builder stage
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy project files
COPY . .
# Install Tailwind and build CSS
RUN DJANGO_SETTINGS_MODULE=django_project.settings.build python manage.py tailwind install
RUN DJANGO_SETTINGS_MODULE=django_project.settings.build python manage.py tailwind build
# Create static and media directories
RUN mkdir -p staticfiles media
# Collect static files
RUN python manage.py collectstatic --noinput
# Change ownership to django user
RUN chown -R django:django /app
# Switch to non-root user
USER django
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD python -c "import requests; requests.get('http://localhost:8000/health/', timeout=10)" || exit 1
# Start server
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "--timeout", "120", "django_project.wsgi:application"]