Last active
December 13, 2023 09:55
-
-
Save aybruhm/c7e120479bb8062edd9e0df07e2d237c to your computer and use it in GitHub Desktop.
A complete docker stack {postgres, pgadmin, redis, celery worker, celery beat, flower} for your python web application.
This file contains 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
version: "3.9" | |
services: | |
api: | |
build: . | |
restart: always | |
container_name: api | |
ports: | |
- "3456:3456" | |
volumes: | |
- .:/api | |
command: > | |
sh -c "<command to run server>" | |
env_file: | |
- ./.env | |
environment: | |
ADMIN_DATABASE_URL: postgresql://${ADMIN_INITDB_ROOT_USERNAME}:${ADMIN_INITDB_ROOT_PASSWORD}@db/${ADMIN_INITDB_DATABASE} | |
depends_on: | |
redis: | |
condition: service_started | |
db: | |
condition: service_healthy | |
db: | |
image: postgres:15.1-alpine | |
container_name: db | |
env_file: | |
- ./.env | |
volumes: | |
- db-data:/var/lib/postgresql/data/ | |
ports: | |
- "5435:5432" | |
environment: | |
POSTGRES_USER: ${ADMIN_INITDB_ROOT_USERNAME} | |
POSTGRES_PASSWORD: ${ADMIN_INITDB_ROOT_PASSWORD} | |
POSTGRES_DB: ${ADMIN_INITDB_DATABASE} | |
healthcheck: | |
test: | |
[ | |
'CMD-SHELL', | |
'pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB' | |
] | |
interval: 10s | |
timeout: 5s | |
retries: 5 | |
pgadmin: | |
image: dpage/pgadmin4 | |
container_name: db_admin | |
restart: always | |
environment: | |
PGADMIN_DEFAULT_EMAIL: admin@root.com | |
PGADMIN_DEFAULT_PASSWORD: admin | |
ports: | |
- "5050:80" | |
volumes: | |
- pgadmin-data:/var/lib/pgadmin | |
redis: | |
image: redis:7.0 | |
container_name: redis | |
worker: | |
build: . | |
restart: always | |
container_name: celery_worker | |
volumes: | |
- .:/api | |
command: python -m celery -A config worker -l info | |
env_file: | |
- ./.env | |
depends_on: | |
redis: | |
condition: service_started | |
beat: | |
build: . | |
restart: always | |
container_name: celery_beat | |
volumes: | |
- .:/api | |
command: python -m celery -A config beat | |
env_file: | |
- ./.env | |
depends_on: | |
redis: | |
condition: service_started | |
flower: | |
image: mher/flower:0.9.7 | |
container_name: celery_analytics | |
command: | |
[ | |
'flower', | |
'--broker=redis://redis:6379', | |
'--port=5555', | |
'--basic_auth=${FLOWER_AUTH_USER}:${FLOWER_AUTH_PASSWORD}' | |
] | |
ports: | |
- "5555:5555" | |
env_file: | |
- ./.env | |
depends_on: | |
redis: | |
condition: service_started | |
volumes: | |
db-data: | |
pgadmin-data: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In your root directory, create a file named
.env
and include the following environment variables:Change the database root username, password, and database before using the environment variables. If you wish to change the database host, make sure to also update the service name in the YAML file. Do not forget to change the auth user and password for flower authentication. Good luck, and happy hacking! 🤓