Docker Compose file · Services
A web app with a database
Two services: an app built from a Dockerfile, and PostgreSQL with a named volume. Keep real passwords in an env file.
services:
web:
build: .
ports:
- "8000:8000"
environment:
DATABASE_URL: postgres://app:${DB_PASSWORD}@db:5432/app
depends_on:
db:
condition: service_healthy
db:
image: postgres:18
environment:
POSTGRES_USER: app
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: app
volumes:
- pgdata:/var/lib/postgresql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U app"]
interval: 5s
retries: 10
volumes:
pgdata:
Official Docker Compose file documentation