DEV Community

Alex Spinov
Alex Spinov

Posted on

Docker Compose v2 Has a Free API That Simplifies Multi-Container Deployments

Docker Compose v2 is a complete rewrite in Go — integrated directly into the Docker CLI as docker compose (no hyphen). It's 40% faster than v1 and adds watch mode, profiles, and GPU support.

v1 vs v2: What Changed

Feature v1 (Python) v2 (Go)
Command docker-compose docker compose
Speed Baseline 40% faster
Watch mode No Yes
GPU support No Yes
Profiles No Yes

Quick Start

# compose.yaml (not docker-compose.yml!)
services:
  web:
    build: .
    ports:
      - "3000:3000"
    develop:
      watch:
        - action: sync
          path: ./src
          target: /app/src
        - action: rebuild
          path: package.json

  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: secret
    volumes:
      - pgdata:/var/lib/postgresql/data

volumes:
  pgdata:
Enter fullscreen mode Exit fullscreen mode

Watch Mode (Game-Changer)

docker compose watch
Enter fullscreen mode Exit fullscreen mode

This watches your source code and automatically syncs changes into running containers — no manual rebuild needed. Three actions: sync (copy files), rebuild (rebuild image), sync+restart.

Profiles — Run Only What You Need

services:
  web:
    build: .

  debug:
    image: busybox
    profiles: ["debug"]

  monitoring:
    image: grafana/grafana
    profiles: ["monitoring"]
Enter fullscreen mode Exit fullscreen mode
docker compose up                          # only 'web' starts
docker compose --profile monitoring up     # web + monitoring
docker compose --profile debug --profile monitoring up  # all
Enter fullscreen mode Exit fullscreen mode

GPU Support

services:
  ml:
    image: pytorch/pytorch
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]
Enter fullscreen mode Exit fullscreen mode

Multi-File Compose

docker compose -f compose.yaml -f compose.prod.yaml up
Enter fullscreen mode Exit fullscreen mode

Override files let you keep dev and prod configs separate without duplicating everything.

Health Checks + Depends On

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

  web:
    build: .
    depends_on:
      db:
        condition: service_healthy
Enter fullscreen mode Exit fullscreen mode

The service_healthy condition means your web app won't start until the database is actually ready — not just "container started."

The Bottom Line

Docker Compose v2 is what v1 should have been. Watch mode alone saves hours of dev time. If you're still using docker-compose (with hyphen), switch now — it's a drop-in replacement.


Need to automate data collection or build custom scrapers? Check out my Apify actors for ready-made tools, or email spinov001@gmail.com for custom solutions.

Top comments (0)