Example Django Project
Dockerfile
FROM python:3.13-alpine
ENV APP_DIR=/app
WORKDIR ${APP_DIR}
COPY pyproject.toml poetry.lock ${APP_DIR}
RUN pip install poetry && poetry install
ADD src ${APP_DIR}/src
WORKDIR ${APP_DIR}/src
#RUN poetry run python manage.py compilemessages
#RUN poetry run python manage.py collectstatic --noinput
EXPOSE 80
CMD ["poetry", "run", "gunicorn", "--bind", ":80", "core.wsgi:application"]
Deploy Django
Django, Postgres, Redis
Docker Compose
networks:
django:
traefik:
external: true
services:
django:
image: ghcr.io/foo/bar:main
env_file: .env
labels:
- traefik.enable=true
- traefik.http.routers.custom_app.rule=Host(`foo.bar`)
- traefik.http.routers.custom_app.entrypoints=tls
- traefik.http.routers.custom_app.tls=true
- traefik.http.routers.custom_app.tls.certresolver=letsencrypt
- traefik.http.routers.custom_app.middlewares=error-pages-middleware
networks:
- django
- traefik
restart: always
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_started
logging:
driver: "json-file"
options:
max-file: "5"
max-size: "10m"
postgres:
image: postgres:16
volumes:
- ./postgres/:/var/lib/postgresql/data/
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
restart: always
networks:
- django
healthcheck:
test: psql -U postgres
interval: 1s
timeout: 10s
retries: 3
redis:
image: redis:7.2
networks:
- django
restart: always
Was this page helpful?