services: db: image: postgres:16 container_name: url_shortener_db restart: always environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: url_db volumes: - postgres_data:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U postgres"] interval: 5s timeout: 5s retries: 5 app: build: . container_name: url_shortener_app depends_on: db: condition: service_healthy environment: DATABASE_URL: postgresql+psycopg2://postgres:postgres@db:5432/url_db BASE_URL: http://localhost:9995 ports: - "9995:9995" volumes: - .:/app # Mount current directory to /app inside container command: > sh -c "alembic upgrade head && uvicorn app.main:app --host 0.0.0.0 --port 9995" volumes: postgres_data: