Linux Containers by Hand. Part 4: Building a container root from image layers
All parts of the series “Linux Containers by Hand”In Parts 2 and 3, nerdctl export gave us a root filesystem with all image layers merged into one directory. In Part 1 we saw that containerd instead mounts an OverlayFS root whose image layers live in separate directories. Today we will inspect the image on disk, unpack the layers ourselves, stack them with OverlayFS, and run nginx on the resulting root. Then we will compare it with the containerd snapshotter’s result.
The script that unpacks and mounts an image’s layers is in the linux-containers-by-hand repository.
Lab setup
| Item | Value |
|---|---|
| Machine | lincont-lab.example.com, 192.168.10.31, Hyper-V VM with 4 vCPUs and 8 GB RAM |
| OS | Ubuntu Server 26.04.1, kernel 7.0.0 |
| containerd and runc | 2.4.2 and 1.5.2 |
| Image | docker.io/library/nginx:1.30-alpine, nginx on Alpine |
Install containerd and runc as in Part 1. Run all commands as root (sudo -i). Install the attr package to inspect extended file attributes.
apt-get install -y attr
The image on disk
Export the image
containerd stores images internally and can export them as tar archives in the standard OCI Image Layout format. --platform keeps only the data for our architecture in the archive.
img=docker.io/library/nginx:1.30-alpine
ctr image pull --platform linux/amd64 $img > /dev/null
mkdir -p /srv/c4/oci
cd /srv/c4
ctr image export --platform linux/amd64 nginx.tar $img
tar -C oci -xf nginx.tar
ls -l nginx.tar
ls oci
cat oci/oci-layout; echo
jq . oci/index.json
-rw-r--r-- 1 root root 26102784 Nov 10 20:10 nginx.tar
blobs
index.json
manifest.json
oci-layout
{"imageLayoutVersion":"1.0.0"}
{
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.index.v1+json",
"manifests": [
{
"mediaType": "application/vnd.oci.image.index.v1+json",
"digest": "sha256:583b7f2fce1cdb8da5ad5c39ebd3c33b98b87d493190e548bdee1fa8c619c311",
"size": 10317,
"annotations": {
"containerd.io/distribution.source.docker.io": "library/nginx",
"io.containerd.image.name": "docker.io/library/nginx:1.30-alpine",
"org.opencontainers.image.ref.name": "1.30-alpine"
}
}
]
}
oci-layoutidentifies the format and its version.blobs/sha256/holds the image data, including JSON and layer archives. Each filename is the SHA-256 digest of its contents. This is content addressing. The name doubles as a checksum and identical blobs can be stored once across images.index.jsonis the entry point with named references. OCI calls each reference a descriptor. It contains themediaType,digest, and size.manifest.jsonprovides compatibility withdocker load. We will leave it aside.
Follow the index to the manifest and configuration
index.json points to another index listing variants for different platforms. Follow that chain. Here and below we show only the first 12 characters of digests.
idx=$(jq -r '.manifests[0].digest' oci/index.json | cut -d: -f2)
jq -c '.manifests[] | [.platform.os + "/" + .platform.architecture + (if .platform.variant then "/" + .platform.variant else "" end), .mediaType, .digest[7:19]]' oci/blobs/sha256/$idx
["linux/amd64","application/vnd.oci.image.manifest.v1+json","bb8f722b4be0"]
["unknown/unknown","application/vnd.oci.image.manifest.v1+json","49c436e1cd67"]
["linux/arm/v6","application/vnd.oci.image.manifest.v1+json","dd71710d7e29"]
["unknown/unknown","application/vnd.oci.image.manifest.v1+json","77e85bf02131"]
["linux/arm/v7","application/vnd.oci.image.manifest.v1+json","346f0b8473c5"]
["unknown/unknown","application/vnd.oci.image.manifest.v1+json","1b6a8154a83e"]
["linux/arm64/v8","application/vnd.oci.image.manifest.v1+json","564a09935b00"]
["unknown/unknown","application/vnd.oci.image.manifest.v1+json","0111684c0a62"]
["linux/386","application/vnd.oci.image.manifest.v1+json","7bec307c2255"]
["unknown/unknown","application/vnd.oci.image.manifest.v1+json","1feda9d64161"]
["linux/ppc64le","application/vnd.oci.image.manifest.v1+json","cabc376da5e4"]
["unknown/unknown","application/vnd.oci.image.manifest.v1+json","65d082a6dd7e"]
["linux/riscv64","application/vnd.oci.image.manifest.v1+json","00c1f2ca460a"]
["unknown/unknown","application/vnd.oci.image.manifest.v1+json","535b703d3abb"]
["linux/s390x","application/vnd.oci.image.manifest.v1+json","b774748ef661"]
["unknown/unknown","application/vnd.oci.image.manifest.v1+json","4219d9fcfd25"]
There are eight platforms, each with a pair of manifests. One is the image manifest and the other, marked unknown/unknown, is an attestation containing information about how the image was built and what went into it. The archive contains the blobs for linux/amd64 only. The other descriptors point to blobs we did not download. Select our platform manifest.
m=$(jq -r '.manifests[] | select(.platform.os == "linux" and .platform.architecture == "amd64") | .digest' oci/blobs/sha256/$idx | cut -d: -f2)
jq -r '.mediaType, (.config | .mediaType + " " + .digest[7:19]), (.layers[] | .mediaType + " " + .digest[7:19] + " " + (.size | tostring))' oci/blobs/sha256/$m
application/vnd.oci.image.manifest.v1+json
application/vnd.oci.image.config.v1+json 1390db6b01a8
application/vnd.oci.image.layer.v1.tar+gzip 881fc932939e 3853673
application/vnd.oci.image.layer.v1.tar+gzip 52eb9c26a936 1883222
application/vnd.oci.image.layer.v1.tar+gzip 89fcb8c38289 627
application/vnd.oci.image.layer.v1.tar+gzip 163ee6b178c7 964
application/vnd.oci.image.layer.v1.tar+gzip 0e13a8a92b02 403
application/vnd.oci.image.layer.v1.tar+gzip c12ffff18732 1209
application/vnd.oci.image.layer.v1.tar+gzip d04b4ed66a45 1396
application/vnd.oci.image.layer.v1.tar+gzip 4fd2a979a136 20321868
The manifest points to the image configuration and eight gzip-compressed tar layers. The list runs from the base at the bottom to the topmost layer. Inspect the configuration.
c=$(jq -r '.config.digest' oci/blobs/sha256/$m | cut -d: -f2)
jq '.config | {Entrypoint, Cmd, Env, ExposedPorts, StopSignal}' oci/blobs/sha256/$c
jq -r '.rootfs.diff_ids[] | .[7:19]' oci/blobs/sha256/$c
jq -r '.history[] | select(.empty_layer != true) | .created_by[0:90]' oci/blobs/sha256/$c
{
"Entrypoint": [
"/docker-entrypoint.sh"
],
"Cmd": [
"nginx",
"-g",
"daemon off;"
],
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NGINX_VERSION=1.30.6",
"PKG_RELEASE=1",
"DYNPKG_RELEASE=1",
"NJS_VERSION=1.0.2",
"NJS_RELEASE=1",
"ACME_VERSION=0.4.1"
],
"ExposedPorts": {
"80/tcp": {}
},
"StopSignal": "SIGQUIT"
}
75f1d9657d88
495c4fa2cdd4
8a4b8e348afa
58eeef868683
3831075a57f3
3abae6d8a7fc
8f5b99f326f2
7249c65f5b3f
ADD alpine-minirootfs-3.24.4-x86_64.tar.gz / # buildkit
RUN /bin/sh -c set -x && addgroup -g 101 -S nginx && adduser -S -D -H -u 101 -h /v
COPY docker-entrypoint.sh / # buildkit
COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d # buildkit
COPY 15-local-resolvers.envsh /docker-entrypoint.d # buildkit
COPY 20-envsubst-on-templates.sh /docker-entrypoint.d # buildkit
COPY 30-tune-worker-processes.sh /docker-entrypoint.d # buildkit
RUN /bin/sh -c set -x && apkArch="$(cat /etc/apk/arch)" && nginxPackages="
containerd uses this configuration to build config.json for runc. It combines Entrypoint and Cmd and reads the environment and stop signal. diff_ids are the hashes of the uncompressed layers. history records the build steps: the Alpine archive first, nginx installation second, and startup scripts after that.
Two digests for one layer
A layer’s filename is the digest of the compressed archive, while diff_ids gives the digest of the uncompressed archive. Check the first layer.
l1=$(jq -r '.layers[0].digest' oci/blobs/sha256/$m | cut -d: -f2)
sha256sum oci/blobs/sha256/$l1
zcat oci/blobs/sha256/$l1 | sha256sum
jq -r '.rootfs.diff_ids[0]' oci/blobs/sha256/$c
881fc932939efef04ca120ad44bbd2c0917851eb247aa4995428afb1e80ede17 oci/blobs/sha256/881fc932939efef04ca120ad44bbd2c0917851eb247aa4995428afb1e80ede17
75f1d9657d880da5f75298e8f40e9928bb6e260c50d26f97af196845307e3064 -
sha256:75f1d9657d880da5f75298e8f40e9928bb6e260c50d26f97af196845307e3064
The compressed archive’s digest matches the filename, which verifies it against the manifest. The uncompressed digest matches the diff_id, which identifies the layer contents independently of compression.
Extract the layers
Extract every layer into a separate directory, from first to last.
i=0
for d in $(jq -r '.layers[].digest[7:]' oci/blobs/sha256/$m); do
i=$((i + 1))
mkdir -p layers/$i
tar -C layers/$i -xzf oci/blobs/sha256/$d
done
du -sh layers/*
for l in layers/*; do echo "$l: $(cd $l && find . -mindepth 1 -maxdepth 3 -not -type d | head -3 | tr '\n' ' ')"; done
8.7M layers/1
5.4M layers/2
8.0K layers/3
12K layers/4
12K layers/5
12K layers/6
16K layers/7
50M layers/8
layers/1: ./lib/ld-musl-x86_64.so.1 ./lib/libc.musl-x86_64.so.1 ./sbin/fstrim
layers/2: ./etc/init.d/nginx ./etc/init.d/nginx-debug ./etc/shadow
layers/3: ./docker-entrypoint.sh
layers/4: ./docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
layers/5: ./docker-entrypoint.d/15-local-resolvers.envsh
layers/6: ./docker-entrypoint.d/20-envsubst-on-templates.sh
layers/7: ./docker-entrypoint.d/30-tune-worker-processes.sh
layers/8: ./etc/fonts/fonts.conf ./etc/ca-certificates.conf ./etc/apk/world
Each layer contains the changes from its build step. The third has just docker-entrypoint.sh. Layers can also delete files from earlier layers. In a layer archive, an empty file with the .wh. prefix is a whiteout. .wh.issue hides issue in that directory, and .wh..wh..opq hides all the directory’s contents from lower layers. Count the whiteouts in the nginx layers.
for d in $(jq -r '.layers[].digest[7:]' oci/blobs/sha256/$m); do tar -tzf oci/blobs/sha256/$d | grep -c '\.wh\.' ; done | paste -sd' '
0 0 0 0 0 0 0 0
This image has no whiteouts, so extraction is enough. For images with whiteouts, the script at the end translates them into the OverlayFS representation shown below.
overlayfs
OverlayFS presents several directories as a single filesystem. It takes four inputs.
lowerdiris a colon-separated list of read-only directories. The topmost lower directory goes first. When names collide, the earliest directory in the list takes precedence.upperdirholds all changes.workdiris a work directory on the same filesystem asupperdir. OverlayFS stages files there before moving them atomically intoupperdir.- The mount point exposes the merged view.
Mount the eight image layers underneath an empty writable container layer.
mkdir -p c1/upper c1/work c1/merged
lower=$(for n in $(seq $i -1 1); do printf '/srv/c4/layers/%s:' $n; done | sed 's/:$//')
echo $lower
mount -t overlay overlay -o lowerdir=$lower,upperdir=/srv/c4/c1/upper,workdir=/srv/c4/c1/work /srv/c4/c1/merged
findmnt -no FSTYPE,OPTIONS /srv/c4/c1/merged
ls c1/merged
ls -A c1/upper | wc -l
ls c1/merged/usr/sbin/nginx layers/*/usr/sbin/nginx
/srv/c4/layers/8:/srv/c4/layers/7:/srv/c4/layers/6:/srv/c4/layers/5:/srv/c4/layers/4:/srv/c4/layers/3:/srv/c4/layers/2:/srv/c4/layers/1
overlay rw,relatime,lowerdir=/srv/c4/layers/8:/srv/c4/layers/7:/srv/c4/layers/6:/srv/c4/layers/5:/srv/c4/layers/4:/srv/c4/layers/3:/srv/c4/layers/2:/srv/c4/layers/1,upperdir=/srv/c4/c1/upper,workdir=/srv/c4/c1/work,uuid=on,nouserxattr
bin
dev
docker-entrypoint.d
docker-entrypoint.sh
etc
home
lib
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
0
c1/merged/usr/sbin/nginx
layers/2/usr/sbin/nginx
merged shows the entire image tree, upper is still empty, and nginx comes from the second layer. The mount options match the container root in Part 1 with our own directories substituted.
Writes and copy-up
Change a file from the first layer.
head -1 c1/merged/etc/motd
echo 'edited in c1' > c1/merged/etc/motd
cat c1/merged/etc/motd
head -1 layers/1/etc/motd
find c1/upper -mindepth 1
Welcome to Alpine!
edited in c1
Welcome to Alpine!
c1/upper/etc
c1/upper/etc/motd
On the first write, OverlayFS copies the whole file into upper and edits that copy. This is copy-up. The lower layer is unchanged. Appending a line to a large image file therefore requires copying the entire file first.
Deletions and whiteouts
rm c1/merged/etc/issue
ls -l c1/upper/etc/issue
ls c1/merged/etc/issue
ls -l layers/1/etc/issue
c--------- 2 root root 0, 0 Nov 10 20:10 c1/upper/etc/issue
ls: cannot access 'c1/merged/etc/issue': No such file or directory
-rw-r--r-- 1 root root 51 Nov 5 09:17 layers/1/etc/issue
OverlayFS cannot remove a file from a read-only lower layer, so it puts a deletion marker in upper, a character device with major and minor numbers 0, 0. That is an OverlayFS whiteout. Convert .wh. files from layer archives to this representation.
Replacing a directory with an opaque directory
Remove the nginx page directory and create a new one with our own page.
rm -r c1/merged/usr/share/nginx/html
mkdir c1/merged/usr/share/nginx/html
echo 'hello from the upper layer' > c1/merged/usr/share/nginx/html/index.html
getfattr -n trusted.overlay.opaque c1/upper/usr/share/nginx/html
ls c1/merged/usr/share/nginx/html
find c1/upper -mindepth 1 | sort
# file: c1/upper/usr/share/nginx/html
trusted.overlay.opaque="y"
index.html
c1/upper/etc
c1/upper/etc/issue
c1/upper/etc/motd
c1/upper/usr
c1/upper/usr/share
c1/upper/usr/share/nginx
c1/upper/usr/share/nginx/html
c1/upper/usr/share/nginx/html/index.html
The new directory has the extended attribute trusted.overlay.opaque="y". An opaque directory hides the contents of any same-named directories in lower layers. The original nginx pages disappear from view. This is the equivalent of .wh..wh..opq.
Run nginx on our root
Build an runc bundle as in Part 2, setting the root to merged and taking the command and environment from the image configuration. Keep the root writable because nginx writes to /var/cache and /run. The root-owned nginx master needs CAP_SETUID and CAP_SETGID to run its workers as nginx, plus CAP_CHOWN to give the user ownership of the cache directories. The runc spec template lacks these capabilities. Part 7 covers them in detail.
mkdir c1/bundle
cd c1/bundle
runc spec
jq --slurpfile img /srv/c4/oci/blobs/sha256/$c '.root = {path: "/srv/c4/c1/merged"} | .hostname = "web" | .linux.cgroupsPath = "/lab/c4" | .process.terminal = false | .process.args = ($img[0].config.Entrypoint + $img[0].config.Cmd) | .process.env = $img[0].config.Env | .process.capabilities[] += ["CAP_SETUID", "CAP_SETGID", "CAP_CHOWN"]' config.json > c.json && mv c.json config.json
jq -c '.root, .process.args, .process.capabilities.bounding' config.json
runc run -d c4 > /srv/c4/c1/nginx.log 2>&1
runc list
runc ps c4
{"path":"/srv/c4/c1/merged"}
["/docker-entrypoint.sh","nginx","-g","daemon off;"]
["CAP_AUDIT_WRITE","CAP_KILL","CAP_NET_BIND_SERVICE","CAP_SETUID","CAP_SETGID","CAP_CHOWN"]
ID PID STATUS BUNDLE CREATED OWNER
c4 9532 running /srv/c4/c1/bundle 2026-11-10T20:10:08.78741401Z root
UID PID PPID C STIME TTY TIME CMD
root 9532 1 0 20:10 ? 00:00:00 nginx: master process nginx -g daemon off;
syslog 9562 9532 0 20:10 ? 00:00:00 nginx: worker process
syslog 9563 9532 0 20:10 ? 00:00:00 nginx: worker process
syslog 9564 9532 0 20:10 ? 00:00:00 nginx: worker process
syslog 9565 9532 0 20:10 ? 00:00:00 nginx: worker process
-d runs the container in the background. runc run creates and starts it and returns immediately. Notice the worker owner, syslog. runc ps uses the host’s view. The image’s nginx user has UID 101, which belongs to syslog on the host. Without a separate user namespace, both see the same numeric IDs. We will return to that in Part 7.
Request a page from inside the container. Over HTTP, a client sends a request such as GET / for the home page, and the server returns a status code, 200 for success, and the content. The container has only lo, so use Alpine’s wget to reach 127.0.0.1.
runc exec c4 wget -qO- http://127.0.0.1/
cat /srv/c4/c1/nginx.log
cd /srv/c4
find c1/upper -mindepth 1 -newer c1/bundle/config.json | sort
hello from the upper layer
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2026/11/10 20:10:08 [notice] 1#1: using the "epoll" event method
2026/11/10 20:10:08 [notice] 1#1: nginx/1.30.6
2026/11/10 20:10:08 [notice] 1#1: built by gcc 15.2.0 (Alpine 15.2.0)
2026/11/10 20:10:08 [notice] 1#1: OS: Linux 7.0.0-43-generic
2026/11/10 20:10:08 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1024:1024
2026/11/10 20:10:08 [notice] 1#1: start worker processes
2026/11/10 20:10:08 [notice] 1#1: start worker process 30
2026/11/10 20:10:08 [notice] 1#1: start worker process 31
2026/11/10 20:10:08 [notice] 1#1: start worker process 32
2026/11/10 20:10:08 [notice] 1#1: start worker process 33
127.0.0.1 - - [10/Nov/2026:20:10:10 +0000] "GET / HTTP/1.1" 200 27 "-" "Wget" "-"
c1/upper/etc/nginx/conf.d
c1/upper/etc/nginx/conf.d/default.conf
c1/upper/run
c1/upper/run/nginx.pid
c1/upper/var/cache/nginx
c1/upper/var/cache/nginx/client_temp
c1/upper/var/cache/nginx/fastcgi_temp
c1/upper/var/cache/nginx/proxy_temp
c1/upper/var/cache/nginx/scgi_temp
c1/upper/var/cache/nginx/uwsgi_temp
nginx served our page from the upper layer. upper also shows what the container wrote at startup. The entrypoint changed default.conf, which copied it up, and nginx wrote its PID and created cache directories.
Start a second container on the same layers
Mount the same layers again with a separate writable layer.
mkdir -p c2/upper c2/work c2/merged
mount -t overlay overlay -o lowerdir=$lower,upperdir=/srv/c4/c2/upper,workdir=/srv/c4/c2/work /srv/c4/c2/merged
head -1 c2/merged/etc/motd
ls c2/merged/usr/share/nginx/html
du -sh layers c1/upper c2/upper
Welcome to Alpine!
50x.html
index.html
64M layers
116K c1/upper
4.0K c2/upper
The second container sees the original image. The first container’s changes live in its own upper directory. All containers using the image share 64 MB of lower layers and store only their own changes separately.
How containerd builds the root
The containerd OverlayFS snapshotter stores each layer in a snapshot, snapshots/<number>/fs, keyed by a chainID. This hash identifies the entire stack from the bottom through that layer. The first chainID equals the first diff_id. Each subsequent chainID is the hash of the previous chainID, a space, and the current diff_id. Compute the chainID for the top nginx layer.
chain=""
for d in $(jq -r '.rootfs.diff_ids[]' oci/blobs/sha256/$c); do
if [ -z "$chain" ]; then chain=$d; else chain=sha256:$(printf '%s %s' $chain $d | sha256sum | cut -d' ' -f1); fi
done
echo $chain
ctr snapshots ls | awk 'NR == 1 || /sha256/ {print substr($1, 1, 19), substr($2, 1, 19), $3}'
sha256:468b69c204cacb66d72681fad0448eb600f754996a1a6660687a3ed5b7cc95c6
KEY PARENT KIND
sha256:3c56e74534e0 sha256:8b413931a5c6 Committed
sha256:468b69c204ca sha256:fae5f49aff77 Committed
sha256:5a11b71abc02 sha256:601a71d7b3ad Committed
sha256:601a71d7b3ad sha256:a709df8bdb2e Committed
sha256:75f1d9657d88 Committed
sha256:8b413931a5c6 sha256:5a11b71abc02 Committed
sha256:a709df8bdb2e sha256:75f1d9657d88 Committed
sha256:fae5f49aff77 sha256:3c56e74534e0 Committed
There are eight snapshots, each referencing its parent. The first, 75f1d9657d88, has no parent and matches the first layer’s diff_id. Our result 468b69c204ca is at the top. Two images with the same base layers share those snapshots because identical layer stacks produce the same chainID.
To prepare a container root, containerd creates an active snapshot above the top image snapshot. That becomes the writable layer. ctr can show the command that mounts it.
ctr snapshots prepare demo $chain > /dev/null
ctr snapshots mounts /mnt demo
ctr snapshots rm demo
mount -t overlay overlay /mnt -o workdir=/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/65/work,upperdir=/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/65/fs,lowerdir=/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/64/fs:/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/63/fs:/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/62/fs:/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/61/fs:/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/60/fs:/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/59/fs:/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/58/fs:/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/57/fs,index=off
It is the same mount we made by hand: eight lower directories and a new snapshot, 65, with writable fs and its own work directory. The extra index=off disables the index OverlayFS uses to preserve hard links when it copies a file up.
Clean up
runc kill c4 KILL; sleep 1; runc delete c4
umount /srv/c4/c1/merged /srv/c4/c2/merged
cd /
rm -rf /srv/c4
rmdir /sys/fs/cgroup/lab
ctr image rm --sync $img
docker.io/library/nginx:1.30-alpine
With --sync, containerd removes the image snapshots immediately. Otherwise its garbage collector cleans them up later. Keep containerd, runc, and the attr package installed.
Unpack and mount the image with a script
unpack-image.sh downloads an image, follows the index to the platform manifest, unpacks layers separately, converts .wh. markers to OverlayFS whiteouts, and mounts the result.
./unpack-image.sh docker.io/library/nginx:1.30-alpine /srv/c4
8 layers mounted at /srv/c4/merged
{"Entrypoint":["/docker-entrypoint.sh"],"Cmd":["nginx","-g","daemon off;"]}
Pass /srv/c4/merged as the root to container.sh from Part 3 or use it as root.path for runc. Clean up with umount /srv/c4/merged and rm -rf /srv/c4.
References
- Image structure on disk. OCI Image Layout, Image Index, Image Manifest, Descriptors
- Configuration fields,
diff_ids, and chainID. OCI Image Configuration - Layer archives and
.wh.whiteouts. OCI Image Layer - Lower and upper layers, copy-up, whiteouts, and opaque directories. Overlay Filesystem
- containerd’s OverlayFS snapshotter. Source code
Next, we create a cgroup v2 group through /sys/fs/cgroup and limit memory, CPU time, and process count without runc.
Only registered users can leave a comment.
Sign in or register to leave a comment.