Docker Compose v2: What Changed?
Docker Compose v2 is a complete rewrite in Go (v1 was Python). It's now a Docker CLI plugin — docker compose instead of docker-compose. Faster, more reliable, and supports profiles.
Quick Start
# compose.yaml (v2 uses this filename by default)
services:
api:
build: ./api
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgres://user:pass@db:5432/mydb
depends_on:
db:
condition: service_healthy
db:
image: postgres:16-alpine
environment:
POSTGRES_PASSWORD: pass
POSTGRES_DB: mydb
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 3s
retries: 5
redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
pgdata:
docker compose up -d
docker compose logs -f api
docker compose down
Profiles: Dev vs Production
services:
api:
build: ./api
ports:
- "3000:3000"
db:
image: postgres:16-alpine
# Only starts with: docker compose --profile debug up
adminer:
image: adminer
ports:
- "8080:8080"
profiles:
- debug
# Only for testing
test-runner:
build: ./tests
profiles:
- test
depends_on:
- api
- db
docker compose up -d # api + db only
docker compose --profile debug up # api + db + adminer
docker compose --profile test run test-runner # run tests
Watch Mode (Hot Reload)
services:
api:
build: ./api
develop:
watch:
- action: sync
path: ./api/src
target: /app/src
- action: rebuild
path: ./api/package.json
docker compose watch # auto-syncs file changes
v1 vs v2 Migration
| v1 | v2 |
|---|---|
docker-compose |
docker compose |
docker-compose.yml |
compose.yaml |
version: "3.8" |
No version needed |
| Python, slower | Go, 2-5x faster |
| Separate binary | Docker plugin |
Need to extract data from any website at scale? I build custom web scrapers — 77 production scrapers running on Apify Store. Email me at spinov001@gmail.com for a tailored solution.
Check out my awesome-web-scraping collection — 400+ tools for extracting web data.
Top comments (0)