Show a minimal Compose file with a web app and a database.
BeginnerConceptDocker Compose
Answer
services:
web:
build: .
ports: ["8080:8000"]
environment:
DATABASE_URL: postgres://app:secret@db:5432/app
depends_on:
db:
condition: service_healthy
db:
image: postgres:16
environment:
POSTGRES_PASSWORD: secret
POSTGRES_USER: app
volumes: [pgdata:/var/lib/postgresql/data]
healthcheck:
test: ["CMD-SHELL", "pg_isready -U app"]
interval: 5s
retries: 10
volumes:
pgdata:
More on Docker Compose
What is Docker Compose and what problem does it solve?Beginner`docker-compose` vs `docker compose`?BeginnerWhat does `depends_on` guarantee?IntermediateHow do containers in Compose reach each other?BeginnerHow does Compose choose the project name and why does it matter?IntermediateWhat is the difference between `ports` and `expose` in Compose?Beginner