All Guides
Advanced15 min read

Docker Compose Stacks

Deploy multi-service Docker Compose stacks with service discovery, networks, volumes, and health checks.

1.Compose File Structure

Define multi-service applications with Docker Compose.

  1. Create docker-compose.yml in your repository root
  2. Define services: web, api, db, redis, worker, etc.
  3. Use depends_on for startup order
  4. Configure networks for service isolation
  5. Define volumes for persistent data
# docker-compose.yml
version: '3.8'
services:
  web:
    build: .
    ports: ["3000:3000"]
    depends_on: [db, redis]
    environment:
      - DATABASE_URL=postgresql://user:pass@db:5432/app
      - REDIS_URL=redis://redis:6379
  
  api:
    build: ./api
    depends_on: [db]
  
  db:
image: postgres:15
    environment:
      POSTGRES_DB: app
      POSTGRES_USER: user
      POSTGRES_PASSWORD: ${DB_PASSWORD}
    volumes: [db_data:/var/lib/postgresql/data]

  redis:
    image: redis:7-alpine
  
volumes:
  db_data:

2.Service Configuration

Configure each service for production.

  1. Set restart: unless-stopped for auto-recovery
  2. Define health checks: healthcheck: test: [...], interval: 30s
  3. Limit resources: deploy: resources: limits: cpus: '0.5', memory: 512M
  4. Use secrets for sensitive config: secrets: [db_password]
  5. Set logging driver: logging: driver: json-file, options: max-size: 10m

3.Networks and Volumes

Isolate services and persist data.

  1. Frontend network: public-facing services (web, api gateway)
  2. Backend network: internal services (db, redis, workers)
  3. Named volumes for database, redis, uploads
  4. Bind mounts for development (code hot-reload)
  5. Volume backup: include in Oxaploy backup policy

4.Health Checks and Dependencies

Ensure services start in correct order and recover from failures.

  1. Database: healthcheck: test: ['CMD-SHELL', 'pg_isready -U postgres'], interval: 10s
  2. Redis: healthcheck: test: ['CMD', 'redis-cli', 'ping'], interval: 10s
  3. Web: healthcheck: test: ['CMD', 'curl', '-f', 'http://localhost:3000/healthz'], interval: 30s
  4. Use depends_on: condition: service_healthy for ordered startup
  5. Oxaploy monitors health checks and restarts unhealthy containers