BM: Baca dalam Bahasa Melayu
World D6: Under the Hood
cgroups: what it can use
You will learn: how cgroups cap a container's memory, CPU and processes, and what happens at the cap.
Checked with Docker Engine 29 on 31 Oct 2026
The problem
One lunchbox has a memory leak. It eats and eats. Your laptop has 16 GB. What happens to the other lunchboxes?
Pick one answer.
Watch
Turn on all three limits. Watch the Limits panel.
What it can use (cgroups)
Limits
- Memory
- No limit: all 16 GB
- CPU
- No limit: all 8 CPUs
- Processes
- No limit
Linux has portion limits called cgroup: A portion limit: how much memory and CPU, and how many processes, a container may use.. A cgroup caps memory, CPU or the number of processes.
Try it
Give a new nginx, web, a 256 MB portion. Then check it with docker stats --no-stream.
Your laptop~
- No open hatches
Lunchboxes (containers)
- No containers yet
Frozen packs (images)
- alpine:3.221 layers · 12.9MB
- nginx:1.30-alpine8 layers · 93.5MB
- node:24-alpine4 layers · 244MB
0 containers (0 running), 3 images, 0 lockers.
Hint
--memory 256m sets the cap. docker stats --no-stream shows it once.Predict
The app keeps eating memory, far past its cap. What does Linux do?
Pick one answer.
Check
Real output. tail /dev/zero eats memory forever. Exit code 137 means “killed”. OOMKilled means out of memory: it hit its cap.
Check
Namespace or cgroup? Sort each one.
Drag a card into a box. Or tap the card, then tap the box.
You did it!
You can now cap what a container may use.
Go deeper (optional)
Docker always puts a container in its own cgroup, but sets no cap unless asked. With cgroup v2, caps live in files: memory.max, cpu.max, pids.max. A CPU cap only slows a box down. It never kills it. Only use tail /dev/zero with a memory cap!
Real mission
docker run -d --name web --memory 256m --cpus 0.5 --pids-limit 100 nginx:1.30-alpinedocker stats --no-stream webdocker rm -f web
0 of 3 steps done · Your ticks are saved.
Bahasa Melayu
Satu bekas ada kebocoran memori. Ia makan dan terus makan. Laptop anda ada 16 GB. Apa jadi pada bekas yang lain?
Linux ada had catuan yang dipanggil cgroups. Satu cgroup (kumpulan kawalan) hadkan memori, CPU atau bilangan proses.
Beri nginx baharu, web, catuan 256 MB. Kemudian semak dengan docker stats --no-stream.
--memory 256m tetapkan had. docker stats --no-stream tunjuknya sekali.Aplikasi itu terus makan memori, jauh melepasi hadnya. Apa Linux buat?
Output sebenar. tail /dev/zero makan memori tanpa henti. Kod keluar 137 maksudnya “dibunuh”. OOMKilled maksudnya kehabisan memori: ia sampai hadnya.
Namespace atau cgroup? Susun setiap satu.
Kini anda boleh hadkan apa yang container boleh guna.
You finished this before. Practice is always welcome!
Official docs: Resource constraints · cgroups(7) · docker container stats
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?