docker compose -f docker-compose.yml -f docker-compose.prod.yml up
version: '3.8' services: api: build: ./app ports: - "3000:3000" environment: - DB_HOST=db - REDIS_HOST=redis depends_on: db: condition: service_healthy healthcheck: test: ["CMD", "curl", "-f", "http://localhost:3000/health"] interval: 30s
project/ ├── docker-compose.yml ├── app/ │ ├── Dockerfile │ └── index.js └── .env a developer's essential guide to docker compose pdf
volumes: db_data:
docker compose down --rmi all # Remove images too docker system prune -a # Deep clean (careful!) Compose Watch (Docker Compose 2.22+) Automatically rebuild and restart on file changes – replaces hot-reload tools. docker compose -f docker-compose
Use a wait-script or dockerize inside your app. 8. Development vs. Production Compose Files Approach 1: Override file
up -d # Start in background down # Stop + remove containers down -v # Also delete volumes restart # Restart all services Development vs
build --no-cache # Rebuild images pull # Pull latest images push # Push built images