Docker Compose V1 to V2 Migration
Update your Docker Compose configuration from V1 to V2 syntax.
Key Changesโ
Version Fieldโ
- version: '3.8'
+ # No version field needed in V2
Commandโ
- docker-compose up -d
+ docker compose up -d
Environment Filesโ
- env_file:
- - .env
+ env_file:
+ - path: .env
+ required: false
Healthchecksโ
db:
healthcheck:
- test: ["CMD-SHELL", "pg_isready"]
+ test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
+ start_period: 30s
Depends On with Conditionsโ
services:
api:
depends_on:
db:
condition: service_healthy
redis:
condition: service_started
Profilesโ
services:
api:
profiles: ["production"]
debug:
profiles: ["debug"]
Run specific profiles: docker compose --profile production up
Full V2 Exampleโ
services:
api:
image: ghcr.io/ever-co/gauzy-api:latest
restart: unless-stopped
depends_on:
db:
condition: service_healthy
env_file:
- path: .env
required: true
ports:
- "3000:3000"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/api/health"]
interval: 30s
timeout: 10s
retries: 3
db:
image: postgres:16
restart: unless-stopped
environment:
POSTGRES_DB: gauzy
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ${DB_PASS}
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
volumes:
pgdata:
Related Pagesโ
- Production Deployment โ deployment guide
- Docker Troubleshooting โ Docker issues