Cap Container CPU and Memory at Run Time
Run containers under tight cgroup ceilings using docker run flags, watch live consumption with docker stats, and trigger the OOM killer to read exit code 137 as the SIGKILL fingerprint.

Lab overview
Every container on a Linux host shares one kernel, one CPU scheduler, and one memory pool. Without resource ceilings, a single runaway process inside a container can pin every core, exhaust RAM, and starve every other workload on the box. Docker exposes a small set of run-time flags that map directly to Linux cgroups v2 controllers: --memory caps RSS, --cpus caps CPU time, and --cpu-shares weights contention. When the kernel sees a container cross its memory ceiling, the OOM killer fires and the container exits with code 137, the SIGKILL fingerprint that operators learn to recognize at a glance.
The same primitives that enforce these flags are the foundation under Kubernetes requests and limits, systemd slices, and every other container runtime in production. A learner who can read docker stats and connect what they see to --memory 128m will later debug evicted pods, throttled workloads, and noisy-neighbor incidents without it feeling like black magic. In this lab, you will run busybox and alpine containers under increasingly tight ceilings, watch live consumption with docker stats, and deliberately push a workload past its memory limit to witness the OOM killer end the process and stamp exit code 137 on the container.
Objectives
Upon completion of this beginner level lab, you will be able to:
- Run a container with no ceilings and capture an unconstrained CPU and memory baseline with
docker stats - Cap a container's memory with
--memoryand disable swap by setting--memory-swapto the same value - Cap CPU time with
--cpusand contrast it against weight-based--cpu-sharesunder contention - Reproduce an OOM kill by exceeding the memory ceiling and identify exit code
137as the SIGKILL fingerprint
Who is this lab for?
This lab is designed for:
- Beginner Docker users who can run basic containers and now need to understand the cgroup-backed resource ceilings underneath
- Platform engineers and SREs preparing to debug evicted Kubernetes pods, throttled workloads, and noisy-neighbor incidents in production
Verified against your live environment
An automated validation engine inspects your actual resources and configurations as you work. Completion means the task was performed, not multiple choice, real-world proficiency.
More labs like this
Running Containers with docker run and kubectl
Run nginx:alpine first with docker run then with kubectl run on the same VM, and see how Kubernetes maps onto Docker concepts.
Deploy Multi-Container Apps with Docker Compose
Author a compose.yaml that runs nginx, a Python API, and Postgres as a single declarative multi-service stack.
Build and Push Images to a Container Registry with Docker
Tag, push, and pull Docker images using a self-hosted registry, applying semver, latest, and content-addressed digest references.
Environment
Every lab includes
- Real environment, pre-credentialed
- Automated checks on every step
- Isolated sandbox, auto cleanup
- AI-recommended next steps
Lab curriculum
- 01
Getting Started with Docker IDE
- 02
Capture Baseline Footprint Without Resource Limits
1 automated check
- 03
Cap Memory and Disable Swap on the Container
1 automated check
- 04
Cap CPU with --cpus and Compare to --cpu-shares
1 automated check
- 05
Trigger the OOM Killer and Read Exit Code 137
1 automated check
Not the lab you were looking for?
Browse 200+ hands-on labs across AWS, Azure, Kubernetes, Docker, and cloud security.