intermediateDocker Compose: Services, Networks, Volumes, Scaling & Health Checks

How would you scale a service with Docker Compose, and what constraint does that introduce?

docker compose up --scale app=3 -d runs three containers from the app service definition. The constraint is that you cannot use a fixed host port mapping (ports: "8080:8080") for a scaled service, since multiple containers can't bind the same host port; instead, use expose (internal-only) and put a load balancer (e.g., nginx) in front to distribute traffic across the replicas.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to What is the difference between docker compose down and docker compose down -v?← Back to all Docker questions