βΆWhen should I use Compose vs Kubernetes for production?
Compose: single-host, < 10 services, simple stateless apps, small team, ~weeks of ops experience. K8s: multi-host clusters, auto-scaling, HA, > 10 services, large teams, months of ops learning. Cost crossover: Compose on t3.large ($30/mo) vs K8s managed ($150+/mo for minimal cluster). For most early-stage startups, Compose wins until you hit 100K+ daily users or need multi-region failover.
βΆHow do I handle persistent data with volumes?
Named volumes (docker volume create mydata, mount: mydata:/db) for stateful services. Host volumes (host:container path) for dev but NOT prod. Volumes survive container restarts, but backup is manual. For production, use external managed DBs (RDS, MongoDB Atlas) instead; Compose is for orchestration, not persistence.
βΆWhat's the difference between BuildKit and the standard Docker build?
BuildKit is 10-50x faster, supports parallel layer builds, better caching, multi-stage secrets. Enable with DOCKER_BUILDKIT=1 docker build. In compose.yml: set buildkit context. Standard build is synchronous, slow for large images. BuildKit is the default in Docker 4.0+.
βΆCan I run Compose on Apple Silicon Macs?
Docker Desktop on M1/M2/M3 works but is 20-30% slower than native arm64 images. Use OrbStack (faster, lighter) or Colima (free, QEMU-based) as alternatives. Specify arm64 images in Dockerfile: FROM --platform=linux/arm64 alpine. Multi-stage builds test on amd64 first to avoid arm64-only breakage in CI.
βΆHow do I debug networking issues between services?
Use 'docker compose exec servicename sh' to enter containers. Test DNS: ping database (service name = DNS hostname in same network). Check logs: 'docker compose logs servicename'. Port mapping: localhost:3000 for host access, but service-to-service uses servicename:port only (not localhost). Network name defaults to dirname_default.
βΆWhat's the recommended pattern for environment variables in compose?
Use .env file (git-ignored) for dev, docker compose --env-file production.env for prod, or Docker secrets for sensitive data (passwords/API keys, mount as read-only /run/secrets/key). Never hardcode secrets in compose.yml. Use ${VARIABLE} syntax in compose.yml to interpolate.
βΆHow do I optimize startup time and multi-stage builds?
Separate build stage from runtime: FROM node AS builder (npm install + compile) β FROM alpine (copy only /dist). BuildKit caches layer-by-layer, so order dependencies before code. Use docker compose --abort-on-container-exit for test runs. Healthchecks (curl http://localhost:3000) ensure service readiness before dependent services start.