Skip to main content
RunBook Academy

← All labs in Docker & Containers

Lab · intermediate · ~25 min

Lab 3: OverlayFS — observing copy-up in real time

B · Nested virtualisationC · Simulation

Objectives

  • Observe OverlayFS layer composition
  • Watch the copy-up of a file when the container writes to it
  • Verify upper-layer / lower-layer behaviour

Prerequisites

  • Lab 2 completed

Objective

Watch OverlayFS copy a file from the image’s lower layer to the container’s upper layer on first write. This is the “copy-up” behaviour that affects write performance and disk usage.

Requirements

  • A Linux host.
  • Docker installed.
  • An image with a known file (e.g. nginx:1.27).

Tasks

Task 1: Start a container

docker run --rm -d --name overlaytest nginx:1.27 sleep 3600
PID=$(docker inspect overlaytest --format '{{.State.Pid}}')
echo "Container PID: $PID"

Task 2: Find the OverlayFS directories

CGROUP=$(cat /proc/$PID/cgroup | awk -F: '{print $3}')
BASE=/sys/fs/cgroup$CGROUP
LOWER=$(cat $BASE/lower)
UPPER=$(cat $BASE/upper)
WORK=$(cat $BASE/work)
echo "Lower: $LOWER"
echo "Upper: $UPPER"
echo "Work: $WORK"

Task 3: Verify the file is in the lower layer

ls -la /var/lib/docker/overlay2/$LOWER/diff/usr/share/nginx/html/index.html

The file exists in the lower layer (image).

Task 4: Modify the file inside the container

docker exec overlaytest sh -c "echo modified > /usr/share/nginx/html/index.html"

Task 5: Check for the whiteout and upper file

ls -la /var/lib/docker/overlay2/$UPPER/diff/usr/share/nginx/html/
md5sum /var/lib/docker/overlay2/$LOWER/diff/usr/share/nginx/html/index.html

The lower layer’s file is unchanged. The upper layer has the modification.

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.