Skip to main content
skill CX Codex

docker-compose — Claude Code skill: compose files and stacks

Teaches the agent to write docker-compose.yml and reason about services, networks and volumes. Useful when your local setup spans several containers.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add BagelHole/DevOps-Security-Agent-Skills --skill docker-compose -a claude-code
Open on GitHub

What docker-compose does

The skill gives the agent reference material on Docker Compose: declaring services in YAML, ordering them with health-checked depends_on, splitting traffic across networks, mounting volumes. It ships sample configs for image builds with args and a target stage, environment from .env, port publishing including ranges, named and bind mounts.

Multi-file setups get their own coverage: an auto-loaded override for development, -f flags for production, profiles for optional services, resource limits under deploy. A command section walks through the lifecycle, builds, log tailing, docker compose run and exec, scaling a service, and the watch mode added in Compose v2.22 with file sync and rebuild actions.

Prerequisites are Docker Engine with the Compose plugin (v2), some Docker familiarity and YAML syntax. On anything older than Compose 2.22 the watch command will not run at all.

What it helps with

  • write a compose file for an app, its database and a cache
  • hold the app back until the database reports healthy
  • isolate frontend and backend on separate networks
  • keep debug-only services behind a profile
  • mount source code for hot reload inside the container

Example prompts for the agent

  • Write a docker-compose.yml for a Node app with Postgres and Redis, and make sure the database starts first.
  • Put the backend on an internal network and expose only the proxy to the host.
  • Split the stack into a base file and a dev override that mounts ./src.

How to install docker-compose

1Skills CLI (Vercel)

npx skills add BagelHole/DevOps-Security-Agent-Skills --skill docker-compose -a claude-code

2Manually: put the files in place

~/.claude/skills/docker-compose/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/docker-compose/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about docker-compose

How do I install docker-compose in Claude Code?

Run npx skills add BagelHole/DevOps-Security-Agent-Skills --skill docker-compose -a claude-code. The skill lands at ~/.claude/skills/docker-compose/SKILL.md.

What does the docker-compose skill do?

It supplies the agent with Compose guidance: service definitions, dependencies, networks, volumes, profiles, multiple files and core commands. The agent draws on it when you ask for a local stack to be built or fixed.

What do I need for it to run?

Docker Engine with the Compose v2 plugin, plus enough YAML to read a config. The docker compose watch mode needs Compose 2.22 or later.

Source text

SKILL.md · MIT
---
name: docker-compose
description: Define and run multi-container Docker applications using Docker Compose. Create compose files, manage service dependencies, configure networks and volumes, and orchestrate local development environments. Use when setting up multi-service applications or development environments.
license: MIT
metadata:
  author: devops-skills
  version: "1.0"
---

# Docker Compose

Orchestrate multi-container applications with declarative YAML configuration.

## When to Use This Skill

Use this skill when:
- Running multi-container applications locally
- Setting up development environments
- Defining service dependencies and networking
- Managing application stacks with multiple services
- Creating reproducible development setups

## Prerequisites

- Docker Engine with Compose plugin (v2)
- Basic Docker knowledge
- YAML syntax understanding

## Basic Configuration

### Simple Application Stack

```yaml
# docker-compose.yml
version: '3.8'

services:
  web:
    build: .
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=development
      - DATABASE_URL=postgres://postgres:secret@db:5432/myapp
    depends_on:
      - db
      - redis

  db:
    image: postgres:15-alpine
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: secret
      POSTGRES_DB: myapp
    volumes:
      - postgres-data:/var/lib/postgresql/data
    ports:
      - "5432:5432"

  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"

volumes:
  postgres-data:
```

## Service Configuration

### Build Options

```yaml
services:
  app:
    build:
      context: ./app
      dockerfile: Dockerfile.dev
      args:
        NODE_VERSION: "20"
      target: development
      cache_from:
        - myapp:cache
    image: myapp:dev
```

### Environment Variables

```yaml
services:
  app:
    environment:
      - NODE_ENV=production
      - API_KEY=${API_KEY}  # From shell or .env file
    env_file:
      - .env
      - .env.local
```

### Port Mapping

```yaml
services:
  web:
    ports:
      - "3000:3000"           # HOST:CONTAINER
      - "127.0.0.1:9229:9229" # Bind to localhost only
      - "8080-8090:8080-8090" # Port range
    expose:
      - "3000"                # Internal only (no host binding)
```

### Volume Mounts

```yaml
services:
  app:
    volumes:
      # Named volume
      - app-data:/app/data
      # Bind mount
      - ./src:/app/src
      # Read-only bind mount
      - ./config:/app/config:ro
      # Anonymous volume (for node_modules)
      - /app/node_modules

volumes:
  app-data:
    driver: local
```

### Dependencies

```yaml
services:
  web:
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_started

  db:
    image: postgres:15
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 5s
      retries: 5
```

## Networking

### Custom Networks

```yaml
services:
  frontend:
    networks:
      - frontend-net

  backend:
    networks:
      - frontend-net
      - backend-net

  db:
    networks:
      - backend-net

networks:
  frontend-net:
    driver: bridge
  backend-net:
    driver: bridge
    internal: true  # No external access
```

### Network Aliases

```yaml
services:
  db:
    networks:
      backend:
        aliases:
          - database
          - postgres

networks:
  backend:
```

## Resource Limits

```yaml
services:
  app:
    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 1G
        reservations:
          cpus: '0.5'
          memory: 256M
```

## Multiple Compose Files

### Override Files

```yaml
# docker-compose.yml (base)
services:
  web:
    image: myapp:latest
    ports:
      - "3000:3000"

# docker-compose.override.yml (development - auto-loaded)
services:
  web:
    build: .
    volumes:
      - ./src:/app/src
    environment:
      - DEBUG=true

# docker-compose.prod.yml (production)
services:
  web:
    deploy:
      replicas: 3
    environment:
      - DEBUG=false
```

### Using Multiple Files

```bash
# Development (uses override automatically)
docker compose up

# Production
docker compose -f docker-compose.yml -f docker-compose.prod.yml up

# Merge and view final config
docker compose -f docker-compose.yml -f docker-compose.prod.yml config
```

## Profiles

```yaml
services:
  web:
    image: myapp

  db:
    image: postgres:15

  debug:
    image: busybox
    profiles:
      - debug

  monitoring:
    image: prometheus
    profiles:
      - monitoring
```

```bash
# Run without profiles (web, db only)
docker compose up

# Run with debug profile
docker compose --profile debug up

# Run with multiple profiles
docker compose --profile debug --profile monitoring up
```

## Commands

### Lifecycle

```bash
# Start services
docker compose up -d

# Start specific service
docker compose up -d web

# Stop services
docker compose stop

# Stop and remove containers
docker compose down

# Stop and remove everything including volumes
docker compose down -v --rmi all

# Restart services
docker compose restart web
```

### Building

```bash
# Build images
docker compose build

# Build without cache
docker compose build --no-cache

# Build and start
docker compose up --build

# Pull latest images
docker compose pull
```

### Monitoring

```bash
# View logs
docker compose logs -f

# View specific service logs
docker compose logs -f web

# View running services
docker compose ps

# View resource usage
docker compose top
```

### Execution

```bash
# Run command in new container
docker compose run --rm web npm test

# Execute in running container
docker compose exec web /bin/sh

# Scale service
docker compose up -d --scale worker=3
```

## Development Workflow

### Watch Mode (Compose v2.22+)

```yaml
services:
  web:
    build: .
    develop:
      watch:
        - action: sync
          path: ./src
          target: /app/src
        - action: rebuild
          path: ./package.json
```

```bash
docker compose watch
```

### Hot Reload Setup

```yaml
services:
  web:
    build:
      context: .
      target: development
    volumes:
      - ./src:/app/src
      - /app/node_modules
    environment:
      - CHOKIDAR_USEPOLLING=true
    command: npm run dev
```

## Common Patterns

### Database Initialization

```yaml
services:
  db:
    image: postgres:15
    volumes:
      - postgres-data:/var/lib/postgresql/data
      - ./init-scripts:/docker-entrypoint-initdb.d:ro
    environment:
      POSTGRES_DB: myapp
```

### Reverse Proxy

```yaml
services:
  proxy:
    image: traefik:v3.0
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./traefik.yml:/etc/traefik/traefik.yml:ro

  web:
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.web.rule=Host(`app.localhost`)"
```

## Common Issues

### Issue: Container Cannot Resolve Service Name
**Problem**: Service can't connect to another service by name
**Solution**: Ensure services are on the same network, check depends_on

### Issue: Volume Permissions
**Problem**: Container can't write to mounted volume
**Solution**: Match container user UID with host, or use named volumes

### Issue: Port Already in Use
**Problem**: Error binding to port
**Solution**: Change host port or stop conflicting service

### Issue: Changes Not Reflected
**Problem**: Code changes don't appear in container
**Solution**: Check volume mounts, rebuild if Dockerfile changed

## Best Practices

- Use named volumes for persistent data
- Define healthchecks for database dependencies
- Use profiles to separate optional services
- Keep secrets in .env files (not committed)
- Use override files for environment-specific config
- Pin image versions for reproducibility
- Use networks to isolate service groups
- Leverage watch mode for development

## Related Skills

- [docker-management](../docker-management/) - Docker fundamentals
- [kubernetes-ops](../../orchestration/kubernetes-ops/) - Production orchestration
- [reverse-proxy](../../../infrastructure/networking/reverse-proxy/) - Production routing

© devops-skills · MIT · BagelHole/DevOps-Security-Agent-Skills

Similar skills

All skills for DevOps and infrastructure →

From the same set129

linux-administration A skill for Linux server work: packages, services, disks, processes, cron and logs. Useful when the agent needs to run commands on a server, not just write code. CX Codex +1 770installs linux-hardening A skill that walks your agent through CIS benchmarks: SSH config, user policy, firewall rules and kernel parameters. Useful when a server heads to production or an audit. CX Codex +1 769installs docker-management Instructions for building multi-stage Dockerfiles, managing container networks, and troubleshooting failed processes. Useful for container deployment and debugging. CX Codex +1 508installs systemd-services Creates and manages systemd service units, timers, and socket activation. Use it to run background apps and configure resource limits under Linux. CX Codex +1 504installs reverse-proxy Configures nginx and Traefik as reverse proxies for TLS termination, path routing, and rate limiting. CX Codex +1 473installs firewall-config A skill that writes and reviews firewall rules: iptables, nftables, UFW and AWS security groups. Useful when you lock down a server perimeter or split a network into zones. CX Codex +1 458installs ssh-configuration Configures OpenSSH clients and servers, handles Ed25519 keys, port forwarding, and bastion jumps for secure Linux server access. CX Codex +1 451installs prometheus-grafana This skill gives your agent templates for Prometheus scraping, PromQL queries and Grafana panels. Handy when a project needs monitoring added. CX Codex +1 449installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor