Lesson 2 of 9
Docker Compose - Local Development Stack
Docker Compose runs your entire local development stack in containers: API, SQL Server, Redis, Seq (log viewer), and RabbitMQ - all with one command (`docker compose up`). Eliminates 'works on my machine' by standardizing the dev environment.
Full Local Development docker-compose.yml
version: "3.9"
services:
# ━━ API ━━
api:
build:
context: .
dockerfile: Dockerfile
target: final # use the optimized final stage
ports:
- "8080:8080"
environment:
ASPNETCORE_ENVIRONMENT: Development
ConnectionStrings__DefaultConnection: "Server=sqlserver;Database=MyAppDb;User Id=sa;Password=Dev!Pass123;TrustServerCertificate=True"
ConnectionStrings__Redis: "redis:6379"
Jwt__SecretKey: "dev-secret-key-32-chars-minimum!!"
Serilog__WriteTo__0__Args__serverUrl: "http://seq:5341"
depends_on:
sqlserver:
condition: service_healthy # wait for SQL Server to be ready
redis:
condition: service_started
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
restart: unless-stopped
networks:
- myapp-net
# ━━ SQL Server 2022 ━━
sqlserver:
image: mcr.microsoft.com/mssql/server:2022-latest
ports:
- "1433:1433"
environment:
ACCEPT_EULA: Y
SA_PASSWORD: "Dev!Pass123"
MSSQL_PID: Developer # free developer edition
volumes:
- sqlserver-data:/var/opt/mssql
healthcheck:
test: /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "Dev!Pass123" -Q "SELECT 1" || exit 1
interval: 10s
timeout: 5s
retries: 10
start_period: 30s
networks:
- myapp-net
# ━━ Redis 7 ━━
redis:
image: redis:7-alpine
ports:
- "6379:6379"
command: redis-server --appendonly yes --requirepass ""
volumes:
- redis-data:/data
networks:
- myapp-net
# ━━ Seq - structured log viewer ━━
seq:
image: datalust/seq:latest
ports:
- "5341:5341" # API (Serilog writes here)
- "5342:80" # Web UI - open http://localhost:5342
environment:
ACCEPT_EULA: Y
volumes:
- seq-data:/data
networks:
- myapp-net
volumes:
sqlserver-data:
redis-data:
seq-data:
networks:
myapp-net:
driver: bridge
# ━━ Commands ━━
# docker compose up → start all services
# docker compose up api --build → rebuild API image
# docker compose logs -f api → stream API logs
# docker compose down -v → stop and remove volumesTip
Tip
Practice Docker Compose Local Development Stack in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
.NET provides a unified platform for building various application types
Practice Task
Note
Practice Task - (1) Write a working example of Docker Compose Local Development Stack from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with Docker Compose Local Development Stack is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready dotnet code.
Finished this lesson?