.NET › Docker & Containerization
What is Docker Compose, and how does it simplify running a multi-container .NET application locally (e.g., API + database + Redis)?
IntermediateAnswer
Docker Compose defines a multi-container application's full topology (services, networks, volumes, environment variables, dependencies) in a single YAML file, letting you start an entire local development environment -- your .NET API, a PostgreSQL database, and a Redis cache -- with one `docker compose up` command, instead of manually running and networking multiple `docker run` commands.
# docker-compose.yml
services:
api:
build: .
ports: ["8080:8080"]
environment:
- ConnectionStrings__Db=Host=db;Database=myapp
depends_on: [db, redis]
db:
image: postgres:16
environment: ["POSTGRES_PASSWORD=devpassword"]
redis:
image: redis:7Real-world example A new developer onboarding to a project runs `docker compose up` once and has a fully working local environment with the API, database, and cache all correctly networked together, without manually installing or configuring PostgreSQL or Redis locally.