Skip to content

Docker Compose Setup

The Docker Compose stack requires only Docker Desktop — no .NET SDK, PostgreSQL, or Python needed locally. It's also the setup used in CI.


Start the full stack

docker compose up -d --build

This starts three services in order:

postgres:16-alpine      ← starts first, health-checked
mock-api (Flask)        ← starts after postgres is healthy
backend (.NET)          ← starts last; runs EF migrations, then app

The backend entrypoint (docker/scripts/backend-entrypoint.sh):

  1. Waits for pg_isready
  2. Runs dotnet ef database update --context CoreDbContext
  3. Runs dotnet ef database update --context MeeshoDbContext
  4. Seeds API_Base_URL=http://mock-api:5000 into the DB
  5. Starts the .NET application

Verify

make docker-smoke
# or manually:
curl http://localhost:5269/health
curl http://localhost:5000/health

Open http://localhost:5269/swagger for the full API explorer.


Common Docker commands

# Stream all service logs
docker compose logs -f

# Stream one service
docker compose logs -f backend
docker compose logs -f mock-api
docker compose logs -f postgres

# Shell access
docker compose exec backend bash
docker compose exec postgres psql -U postgres -d dms-layered

# Restart a single service (e.g. after code change)
docker compose restart backend

# Rebuild one service
docker compose build backend

# Stop (preserves database volume)
docker compose down

# Stop + wipe database
docker compose down -v

# Full reset (rebuild from scratch)
docker compose down -v && docker compose up -d --build

Connection strings inside Docker

Inside the Docker network, services communicate using their service names, not localhost:

From To Host to use
backend postgres Server=postgres;Port=5432
backend mock-api http://mock-api:5000
your browser backend http://localhost:5269
your browser mock-api http://localhost:5000

docker-compose.yml injects ConnectionStrings__DefaultConnection with Server=postgres via environment variable — the appsettings.json value (Server=localhost) is overridden inside Docker. No file changes needed.


Port conflicts

If 5269, 5000, or 5432 are already bound on your machine (by a local backend or PostgreSQL), Docker Compose will fail to bind the ports.

# Find what's using a port
lsof -i :5269
lsof -i :5432

Stop the local process, then re-run docker compose up -d.