Blog
Oct 6, 2025 - 9 MIN READ
Docker Compose Mastery: Multi-Container Development Environments for ASP.NET Core

Docker Compose Mastery: Multi-Container Development Environments for ASP.NET Core

Complete guide to using Docker Compose for realistic local development environments, including database integration, networking, and production-like scenarios.

Your Name

Your Name

One of the most impactful tools I've integrated into my development workflow is Docker Compose. Instead of spending hours setting up local databases, I can spin up an entire development environment with a single command.

Why Docker Compose Changes Everything

Before Docker Compose, my development setup was fragile. Each team member had slightly different database versions and configurations. Today, docker-compose up brings up a production-like environment in seconds.

Basic Docker Compose Setup

version: '3.8'

services:
  api:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8080:8080"
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ConnectionStrings__DefaultConnection=Server=sqlserver;Database=AppDb;User Id=sa;Password=YourPassword123!;Encrypt=false;
    depends_on:
      - sqlserver
    volumes:
      - .:/app

  sqlserver:
    image: mcr.microsoft.com/mssql/server:2022-latest
    environment:
      ACCEPT_EULA: Y
      SA_PASSWORD: YourPassword123!
    ports:
      - "1433:1433"
    volumes:
      - sqlserver-data:/var/opt/mssql

  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"
    volumes:
      - redis-data:/data

volumes:
  sqlserver-data:
  redis-data:

Development Dockerfile

The Dockerfile for development differs significantly from production:

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS development
WORKDIR /app

COPY ["MyApi/MyApi.csproj", "./MyApi/"]
RUN dotnet restore "MyApi/MyApi.csproj"

COPY . .

ENTRYPOINT ["dotnet", "watch", "--project", "MyApi/MyApi.csproj", "run"]

Common Tasks

Running Database Migrations

docker-compose exec api dotnet ef database update

Viewing Logs

docker-compose logs -f api

Stopping Services

docker-compose down -v

Conclusion

Docker Compose has transformed how I work. Instead of maintaining complex local setups, I have reproducible, version-controlled development environments.

Built with Nuxt UI • © 2025 Behnam Nouri