PostgreSQL is an open-source relational database for applications that outgrow a file-based SQLite database. Docker Compose can run the application and database as separate services. section 7.4
A Compose configuration connects the application to PostgreSQL by:
- Running a PostgreSQL service from the diamol/postgres:2e-12 image. section 7.4
- Publishing container port 5432 as host port 5433 and exposing the service as todo-db on the Compose network. section 7.4
- Selecting the Postgres provider through Database:Provider and supplying the connection string through a mounted secret file. section 7.4
Listing 7.3 Compose services for an app with a Postgres database
services:
todo-db:
image: diamol/postgres:2e-12
ports:
- "5433:5432"
networks:
- app-net
todo-web:
image: diamol/ch06-todo-list:2e
ports:
- "8020:80"
environment:
- Database:Provider=Postgres
depends_on:
- todo-db
networks:
- app-net
secrets:
- source: postgres-connection
target: /app/config/secrets.json
Inspect the complete Compose services for the PostgreSQL database and to-do application. section 7.4
Run the application
From the exercise directory, run docker compose up -d, or use the Windows Compose file, then run docker compose ps to verify the containers.










