feat: Docker Compose deployment with Nginx and Gunicorn

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Stephan Kerkman 2026-05-28 10:07:18 +02:00
parent 370a02e00e
commit a94cf6fe1e
3 changed files with 70 additions and 0 deletions

14
Dockerfile Normal file
View file

@ -0,0 +1,14 @@
FROM python:3.12-slim
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends \
libpq-dev gcc \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000

32
docker-compose.yml Normal file
View file

@ -0,0 +1,32 @@
services:
web:
build: .
env_file: .env
volumes:
- db:/app/db.sqlite3
- media:/app/media
- static:/app/staticfiles
expose:
- "8000"
command: >
sh -c "python manage.py migrate --noinput &&
python manage.py collectstatic --noinput &&
gunicorn plantdb.wsgi:application --bind 0.0.0.0:8000 --workers 2"
restart: unless-stopped
nginx:
image: nginx:alpine
ports:
- "80:80"
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
- media:/app/media:ro
- static:/app/staticfiles:ro
depends_on:
- web
restart: unless-stopped
volumes:
db:
media:
static:

24
nginx/default.conf Normal file
View file

@ -0,0 +1,24 @@
upstream django {
server web:8000;
}
server {
listen 80;
client_max_body_size 20M;
location /static/ {
alias /app/staticfiles/;
}
location /media/ {
alias /app/media/;
}
location / {
proxy_pass http://django;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}