Skip to main content
RunBook Academy

← All labs in Docker & Containers

Lab · intermediate · ~30 min

Lab 2: Inspecting cgroups — what limits actually apply

B · Nested virtualisationC · Simulation

Objectives

  • Find the cgroup of a running container process
  • Read the memory and CPU limits from cgroup files
  • Reproduce an OOM kill and observe the kernel response

Prerequisites

  • Basic Linux familiarity
  • Docker installed

Objective

Docker’s resource limits are Linux cgroup limits. This lab shows the cgroup files that actually apply to a container’s processes, and demonstrates the OOM-killer’s behaviour when the limit is reached.

Requirements

  • A Linux host (kernel 5.15+ recommended).
  • Docker installed.
  • A container to inspect.

Tasks

Task 1: Find the cgroup of a container’s process

Start a container:

docker run --rm -d --name cgrouptest --memory 256m --cpus 1.5 \
  nginx:1.27 sleep 3600

Find the container’s PID and its cgroup:

PID=$(docker inspect cgrouptest --format '{{.State.Pid}}')
echo "Container PID: $PID"

cat /proc/$PID/cgroup

Task 2: Read the cgroup resource limits

CGROUP=$(cat /proc/$PID/cgroup | awk -F: '{print $3}')
BASE=/sys/fs/cgroup$CGROUP

cat $BASE/memory.max
cat $BASE/cpu.max
cat $BASE/pids.max

Task 3: Try to OOM the container

docker exec cgrouptest sh -c "dd if=/dev/zero of=/dev/shm/test bs=1M count=300"

This should fail because the cgroup limit is 256 MB.

Task 4: Check the kernel’s response

sudo dmesg | tail -20

Task 5: Verify the OOMKilled flag

docker inspect cgrouptest --format '{{.State.OOMKilled}} {{.State.ExitCode}}'

Task 6: Clean up

docker stop cgrouptest

Verification status

Last reviewed
2026-08-09
Executed end to end
not yet run on hardware

The commands and configuration here have been reviewed against the verified software versions, but nobody has run this lab start to finish on a system meeting its prerequisites. Treat the Expected Outcome as the intended result rather than an observed one, and keep the Cleanup section to hand.