Docker Compose scaling

Topic: Containers core

Summary

Scale a Compose service with docker compose up -d --scale app=3. Use for dev or load testing. For production use an orchestrator. Use when you need multiple replicas.

Intent: How-to

Quick answer

  • Run docker compose up -d --scale web=3. Replicas get unique names. All on same network.
  • No built-in load balancer. Use reverse proxy or round-robin. Compose scale is for dev or simple cases.
  • For production use Kubernetes or Swarm for health checks and rolling updates.

Prerequisites

Steps

  1. Scale up

    docker compose up -d --scale web=3. Check docker compose ps for multiple web containers.

  2. Access

    Use proxy or direct ports. Compose does not assign one port per replica by default.

  3. Scale down

    docker compose up -d --scale web=1 or change file and up again.

Summary

Use —scale for multiple replicas; use proxy for access. Use orchestrators for production.

Prerequisites

Steps

Step 1: Scale up

Run compose up with —scale web=3.

Step 2: Access

Use reverse proxy or port mapping.

Step 3: Scale down

Reduce scale or change compose and up.

Verification

  • Multiple containers run; traffic reaches them.

Troubleshooting

Port conflict — Use proxy or different ports. Stateful — Shared storage or session affinity needed.

Next steps

Continue to