version: '3.8'
services:
db:
image: postgres:15-alpine
env_file:
- ./db/.db.env
ports:
- "5433:5432" # На хосте используем 5433, если 5432 занят вашей Windows
volumes:
- pg_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
db-init:
build: ./backend
env_file:
- ./db/.db.env
# Мапим localhost внутрь контейнера на IP-адрес контейнера db
extra_hosts:
- "localhost:db"
depends_on:
db:
condition: service_healthy
command: sh -c "python init_db.py && python init_data.py"
backend:
build: ./backend
env_file:
- ./db/.db.env
# Точно так же перенаправляем localhost бэкенда на контейнер db
extra_hosts:
- "localhost:db"
depends_on:
db-init:
condition: service_completed_successfully
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/"]
interval: 5s
timeout: 5s
retries: 5
frontend:
image: nginx:alpine
ports:
- "8189:80"
volumes:
- ./frontend/nginx.conf:/etc/nginx/conf.d/default.conf:ro
- ./frontend/styles.css:/usr/share/nginx/html/static/styles.css:ro
depends_on:
backend:
condition: service_healthy
volumes:
pg_data: