mcpField
D
docker-compose

docker-compose

github.com/claude-dev-suiteCloud & DevOps4644 installsUpdated 3d ago
Repository

About docker-compose

A quick-reference skill for defining and operating multi-service applications with Docker Compose. It gives developers configuration examples, commands, troubleshooting guidance, and production-readiness practices.

Key features

  1. 01Multi-service Compose examples
  2. 02Start and stop commands
  3. 03Development overrides
  4. 04Environment file configuration
  5. 05Production security and health checks
  6. 06Networking and troubleshooting

Use cases

  1. 01Running an application with its dependencies
  2. 02Separating development and production settings
  3. 03Diagnosing service, network, or volume issues

MCP support

The skill references `mcp__documentation__fetch_docs` to retrieve comprehensive Docker Compose documentation.

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/claude-dev-suite/claude-dev-suite --skill docker-compose

After installing, type/docker-composein Claude Code to confirm it loaded.

Bundled filesquick-ref/commands.mdquick-ref/services.md

Details

From the project README

Docker Compose Core Knowledge

Deep Knowledge: Use mcp__documentation__fetch_docs with technology: docker-compose for comprehensive documentation.

Full Stack Example

# docker-compose.yml
services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "3000:3000"
    environment:
      - DATABASE_URL=postgresql://user:pass@db:5432/mydb
      - REDIS_URL=redis://redis:6379
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_started
    volumes:
      - ./src:/app/src  # Dev hot reload
    networks:
      - app-network

  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: pass
      POSTGRES_DB: mydb
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U user -d mydb"]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - app-network

  redis:
    image: redis:7-alpine
    volumes:
      - redis_data:/data
    networks:
      - app-network

volumes:
  postgres_data:
  redis_data:

networks:
  app-network:
    driver: bridge

Common Commands

# Start services
docker-compose up -d
docker-compose up --build  # Rebuild images

# Stop
docker-compose down
docker-compose down -v     # Remove volumes too

# Logs
docker-compose logs -f app
docker-compose logs --tail=100 app

# Execute
docker-compose exec app sh
docker-compose exec db psql -U user mydb

# Scale
docker-compose up -d --scale app=3

Override for Dev

# docker-compose.override.yml (auto-loaded)
services:
  app:
    build:
      target: development
    volumes:
      - .:/app
      - /app/node_modules
    command: npm run dev

Environment Files

services:
  app:
    env_file:
      - .env
      - .env.local

When NOT to Use This Skill

Skip this skill when:

  • Creating single-container Dockerfiles - use docker skill
  • Deploying to production Kubernetes clusters - use kubernetes skill
  • Setting up CI/CD workflows - use github-actions skill
  • Working with Docker Swarm (deprecated) - use kubernetes skill
  • Building Docker images only (no orchestration needed) - use docker skill

Anti-Patterns

Anti-PatternProblemSolution
Hardcoding ports in composePort conflicts, inflexibleUse ${PORT:-3000}:3000 with env vars
No health checksServices start before readyAdd healthcheck and depends_on.condition
Exposing all ports publiclySecurity riskBind to 127.0.0.1:port for local only
Using latest tagsUnpredictable behaviorPin specific versions postgres:16-alpine
Storing secrets in compose fileSecret exposureUse Docker secrets or env files (gitignored)
No resource limitsResource exhaustionSet deploy.resources.limits
Mixing dev and prod configConfiguration driftUse docker-compose.override.yml and .prod.yml
Not using named volumesData loss on recreationUse named volumes for persistence
Services on default networkNo isolationCreate custom networks per tier
Running as rootSecurity vulnerabilitySet user: "1000:1000" or use Dockerfile USER

Quick Troubleshooting

IssueDiagnosisFix
Service won't startDependency not readyAdd depends_on with condition: service_healthy
Port already in useAnother service using portChange port mapping or stop conflicting service
Database connection refusedService name wrong, network issueUse service name as host: db:5432 not localhost
Changes not reflectedOld containers runningRun docker-compose down && docker-compose up --build
Volume data not persistingUsing anonymous volumesUse named volumes in top-level volumes:
"network not found"Network removed or wrong nameRun docker-compose up to recreate networks
Can't connect between servicesDifferent networksPut services on same network
Environment variables not workingWrong syntax, not loadedUse ${VAR:-default} and check .env file
"service unhealthy"Health check failingCheck docker-compose logs and fix health endpoint
Slow startup on Mac/WindowsVolume mounting overheadUse named volumes instead of bind mounts for dependencies

Production Readiness

Security Configuration
# docker-compose.prod.yml
services:
  app:
    image: myapp:${VERSION:-latest}
    security_opt:
      - no-new-privileges:true
    read_only: true
    tmpfs:
      - /tmp
    cap_drop:
      - ALL
    cap_add:
      - NET_BIND_SERVICE
    user: "1000:1000"
    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 2G
        reservations:
          cpus: '0.5'
          memory: 512M

  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_PASSWORD_FILE: /run/secrets/db_password
    secrets:
      - db_password
    volumes:
      - postgres_data:/var/lib/postgresql/data:Z

secrets:
  db_password:
    file: ./secrets/db_password.txt
Health Checks
services:
  app:
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

  db:
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U $POSTGRES_USER -d $POSTGRES_DB"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 3
Networking
services:
  app:
    networks:
      - frontend
      - backend
    ports:
      - "127.0.0.1:3000:3000"  # Only localhost

  db:
    networks:
      - backend
    # No ports exposed externally

  nginx:
    networks:
      - frontend
    ports:
      - "80:80"
      - "443:443"

networks:
  frontend:
    driver: bridge
  backend:
    driver: bridge
    internal: true  # No internet access
Logging
services:
  app:
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"
        labels: "service,environment"
    labels:
      - "service=app"
      - "environment=production"

  # Or use external logging
  app:
    logging:
      driver: fluentd
      options:
        fluentd-address: localhost:24224
        tag: "docker.{{.Name}}"
Restart Policies
services:
  app:
    restart: unless-stopped
    deploy:
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3
        window: 120s

  db:
    restart: always
Backup Strategy
services:
  backup:
    image: postgres:16-alpine
    entrypoint: /bin/sh
    command: -c "pg_dump -h db -U $$POSTGRES_USER $$POSTGRES_DB | gzip > /backups/backup_$$(date +%Y%m%d_%H%M%S).sql.gz"
    environment:
      PGPASSWORD_FILE: /run/secrets/db_password
    secrets:
      - db_password
    volumes:
      - ./backups:/backups
    depends_on:
      db:
        condition: service_healthy
    profiles:
      - backup
Testing
# docker-compose.test.yml
services:
  test:
    build:
      context: .
      target: test
    environment:
      - DATABASE_URL=postgresql://test:test@db-test:5432/testdb
    depends_on:
      db-test:
        condition: service_healthy
    command: npm test

  db-test:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: test
      POSTGRES_PASSWORD: test
      POSTGRES_DB: testdb
    tmpfs:
      - /var/lib/postgresql/data  # In-memory for speed
# Run tests
docker-compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from test
Monitoring Metrics
MetricTarget
Container uptime> 99.9%
Health check pass rate100%
Restart count< 1/day
Memory usage< 80% limit
Checklist
  • Security opts (no-new-privileges, read_only)
  • Resource limits (CPU, memory)
  • Health checks on all services
  • Internal networks for databases
  • Secrets management (not env vars)
  • Logging with rotation
  • Restart policies configured
  • Backup strategy defined
  • Test compose file
  • Production override file

Reference Documentation

Comments

Markdown supported