BM: Baca dalam Bahasa Melayu
World D4: Set Meals
Scale a service
You will learn: to run more copies of one service, and when you can't.
Checked with Docker Engine 29 on 31 Oct 2026
The problem
Lunch rush! One API cook can’t keep up. You want three. What do you do?
Pick one answer.
Watch
Your laptop~/kedai-kancil
- No open hatches
Lunchboxes (containers)
- No containers yet
Frozen packs (images)
- kedai-kancil-api:latest6 layers · 244MB
- kedai-kancil-web:latest9 layers · 92.6MB
- nginx:1.30-alpine8 layers · 93.5MB
- node:24-alpine4 layers · 244MB
- postgres:18-alpine9 layers · 433MB
- redis:8-alpine7 layers · 162MB
0 containers (0 running), 6 images, 0 lockers.
To scale: Run more copies of one service: docker compose up -d --scale api=3. a service is to run more copies of it. --scale api=3 asks for three. Compose numbers them: api-1, api-2, api-3.
Try it
The rush is over. Keep just two api cooks.
Your laptop~/kedai-kancil
- Laptop port 8080 → kedai-kancil-web-1 port 80
Lunchboxes (containers)
- kedai-kancil-api-1running
- kedai-kancil-api-2running
- kedai-kancil-api-3running
- kedai-kancil-web-1running
Frozen packs (images)
- kedai-kancil-api:latest6 layers · 244MB · in use
- kedai-kancil-web:latest9 layers · 92.6MB · in use
- nginx:1.30-alpine8 layers · 93.5MB
- node:24-alpine4 layers · 244MB
- postgres:18-alpine9 layers · 433MB
- redis:8-alpine7 layers · 162MB
Phone lines (networks)
- kedai-kancil_defaultkedai-kancil-api-1 ↔ kedai-kancil-api-2 ↔ kedai-kancil-api-3 ↔ kedai-kancil-web-1
4 containers (4 running), 6 images, 0 lockers.
Hint
docker compose up -d --scale api=2Predict
Now you scale web to two. Both copies want hatch 8080 on your laptop. What happens?
Pick one answer.
Check
Your laptop~/kedai-kancil
- No open hatches
Lunchboxes (containers)
- No containers yet
Frozen packs (images)
- kedai-kancil-api:latest6 layers · 244MB
- kedai-kancil-web:latest9 layers · 92.6MB
- nginx:1.30-alpine8 layers · 93.5MB
- node:24-alpine4 layers · 244MB
- postgres:18-alpine9 layers · 433MB
- redis:8-alpine7 layers · 162MB
0 containers (0 running), 6 images, 0 lockers.
Real words: port is already allocated. Plain words: web-1 already holds hatch 8080.
Check
Can this dish scale on one laptop? Right for yes, left for no.
Swipe right for good, left for needs work. Or use the buttons.
api with no ports
You did it!
You can now run more copies of one service.
Go deeper (optional)
deploy: replicas: 3 in the file does the same as the flag. Asking for api on the phone line now finds all three boxes. Docker doesn’t truly share the work between them. A proxy does that, or Kubernetes in Part 3. Compose runs on one machine only.
Real rep (optional): in a project with an api service and no ports, run docker compose up -d --scale api=3, then docker compose ps.
Bahasa Melayu
Waktu makan tengah hari! Seorang tukang masak API tak menang tangan. Anda mahu tiga. Apa anda buat?
Scale (skala) satu service bermaksud jalankan lebih banyak salinannya. --scale api=3 minta tiga. Compose beri nombor: api-1, api-2, api-3.
Waktu sibuk dah tamat. Simpan dua tukang masak api sahaja.
docker compose up -d --scale api=2Sekarang anda skala web jadi dua. Kedua-dua salinan mahu tingkap 8080 di laptop. Apa jadi?
Kata sebenar: port is already allocated. Maksudnya: web-1 dah pegang tingkap 8080.
Boleh hidangan ini diskala di satu laptop? Kanan untuk ya, kiri untuk tidak.
Kini anda boleh jalankan lebih banyak salinan satu service.
You finished this before. Practice is always welcome!
Official docs: docker compose up --scale · Compose Deploy Specification: replicas · Compose file reference: container_name
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?