Last active
August 1, 2023 13:03
-
-
Save 50-Course/f6826d10af9f5cbb185868e77f2fce1e to your computer and use it in GitHub Desktop.
Compose file template for python backend applications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############## | |
# Docker Compose File | |
# Maintainer: Eri Adeodu (@50-Course) | |
# License: MIT License. | |
# | |
# Reference links: | |
# incase you feeling adventerous, | |
# - https://docs.docker.com/compose/compose-file/ | |
# - https://nickjanetakis.com/blog/best-practices-around-production-ready-web-apps-with-docker-compose | |
# - https://https://hackmamba.io/blog/2022/09/best-practices-when-using-docker-compose/ | |
############## | |
x-app: &base-app | |
build: | |
context: . | |
args: | |
- "UID=${UID:-1000}" | |
- "GID=${GID:-1000}" | |
env_file: | |
- ".env" | |
restart: "${DOCKER_RESTART_POLICY:-unless-stopped}" | |
tty: true | |
volumes: | |
- "${DOCKER_MOUNTED_VOLUME:-./public_sda:/app/public_sda}" | |
services: | |
backend: | |
<<: *base-app | |
container_name: backend-app | |
command: > | |
sh -c " | |
python /app/manage.py makemigrations api && | |
python /app/manage.py makemigrations && | |
python /app/manage.py migrate && | |
python /app/manage.py collectstatic && | |
python /app/manage.py runserver 0.0.0.0:8000 | |
" | |
healthcheck: | |
test: curl http://0.0.0.0:8000/ || exit 1 | |
interval: 1m30s | |
timeout: 40s | |
retries: 3 | |
start_period: 30s | |
depends_on: | |
- db | |
- redis | |
ports: | |
- "8000:8000" | |
db: | |
image: postgres:14.5-bullseye | |
container_name: main_db | |
deploy: | |
resources: | |
limits: | |
cpus: "${DOCKER_MAX_ALLOWED_CPUS:-0}" | |
memory: "${DOCKER_MAX_ALLOWED_MEMORY:-0}" | |
restart: "${DOCKER_RESTART_POLICY:-unless-stopped}" | |
ports: | |
- 5432 | |
volumes: | |
- "db:/var/lib/postgresql/data" | |
celery: | |
build: | |
context: . | |
command: celery -A core worker -B -l info | |
depends_on: | |
- backend | |
- redis | |
redis: | |
image: redis:6-alpine | |
volumes: | |
db: {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment