Back to results for “Docker & Containerization”
.NET › Docker & Containerization

What is Docker Compose, and how does it simplify running a multi-container .NET application locally (e.g., API + database + Redis)?

Intermediate

Answer

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:7
Real-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.

Common follow-ups: How does depends_on differ from actually waiting for a dependency to be ready?;How does .NET Aspire relate to and potentially replace Docker Compose for local orchestration?