A multicontainer configuration declaratively defines how an application’s containers are built and run. Docker Compose stores service build instructions, storage, environment variables, networks, dependencies, and restart behavior in one YAML file. section 12.5
version: '3'
services:
db: #1
container_name: tutor-postgres
restart: always
image: postgres:latest
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=ezytutors
volumes:
- tutor-data:/var/lib/postgresql/data
- ./c12-data/initdb.sql:/docker-entrypoint-initdb.d/initdb.sql
- ./c12-data/init-tables.sql:/docker-entrypoint-initdb.d/init-tables.sql
ports:
- 5432:5432
networks:
- tutor-network
api: #2
restart: on-failure
container_name: tutor-webservice
build: #3
context: ./
dockerfile: Dockerfile-tutor-webservice
network: host
environment: #4
- DATABASE_URL=${DATABASE_URL}
- HOST_PORT=${HOST_PORT}
depends_on:
- db #5
ports:
- ":3000:3000" #6
networks:
- tutor-network #7
volumes:
tutor-data:
networks:
tutor-network:
The configuration declares a PostgreSQL db service and an api service, connecting them through shared networking and persistent database storage. section 12.5
EzyTutors service stack
A Compose file defines tutor-postgres from the postgres:latest image and tutor-webservice from Dockerfile-tutor-webservice. Environment variables provide DATABASE_URL and HOST_PORT; the database uses a named volume and initialization scripts. Commands such as docker compose build api, docker compose up -d, and curl localhost:3000/tutors/ build, start, and verify the stack. section 12.5
