Seeing Container Filesystem Changes with docker diff
How to inspect runtime container filesystem mutations using docker diff, understanding A (Added), C (Changed), and D (Deleted) status codes, and auditing RW layer state.
Published on • November 18, 2026
AI Assistant

When a container runs, any files written, modified, or deleted by application processes land in the container’s top-level ephemeral Read-Write (RW) layer. Knowing exactly what files have mutated during runtime is critical for debugging unexpected behavior, identifying missing volume mounts, and conducting security forensic investigations.
The docker diff command inspects a running or stopped container and lists all filesystem modifications relative to its underlying base image.
In this tutorial, we will explore how docker diff works, understand its file status symbols, and walk through practical debugging scenarios.
How docker diff Works
Every container consists of a stack of immutable read-only image layers topped with a single thin read-write container layer:
+-----------------------------------------------------------------------------------+
| Container Read-Write Layer (Ephemeral Runtime Changes) |
| - File A created -> Marked 'A' |
| - File B modified -> Marked 'C' |
| - File C removed -> Marked 'D' |
+-----------------------------------------------------------------------------------+
| Read-Only Image Layers (Base OS, Application Code, Static Assets) |
+-----------------------------------------------------------------------------------+
Executing docker diff <container_name> scans the storage driver’s copy-on-write (CoW) delta layer and reports every file path modified since the container started.
Understanding docker diff Status Codes
docker diff outputs a list of file paths prefixed by a single-character change code:
| Symbol | Status | Meaning |
|---|---|---|
A | Added | A new file or directory was created in the container RW layer. |
C | Changed | An existing file or directory inherited from the base image was modified. |
D | Deleted | A file or directory inherited from the base image was deleted. |
Practical Example Walkthrough
Let’s test docker diff on an interactive Ubuntu container:
-
Launch a background container:
docker run -d --name test-box ubuntu:22.04 sleep 3600 -
Execute commands that modify the filesystem:
# Add a new file docker exec test-box bash -c "echo 'hello world' > /tmp/test.txt" # Modify an existing system configuration file docker exec test-box bash -c "echo 'export FOO=bar' >> /etc/bash.bashrc" # Delete a default file docker exec test-box bash -c "rm /etc/legal" -
Inspect changes with
docker diff:docker diff test-box
Sample Output:
C /etc
D /etc/legal
C /etc/bash.bashrc
C /tmp
A /tmp/test.txt
Notice how docker diff instantly pinpoints:
A /tmp/test.txt: The newly created test file.C /etc/bash.bashrc: The modified configuration.D /etc/legal: The deleted file.
Essential Practical Use Cases
1. Identifying Unmounted Persistent Data
If a containerized database (such as Postgres or MySQL) runs slowly or loses data upon restart, run docker diff <container>. If you see hundreds of .db or .log files marked as A inside /var/lib/postgresql/data, it proves that you forgot to attach a persistent volume mount! All data is currently writing to the slow ephemeral container layer.
2. Security Forensics & Malware Triage
If an intrusion detection system flags anomalous process activity in a running container, execute docker diff immediately to see if an attacker installed unauthorized binaries (e.g. A /tmp/miner), modified /etc/passwd, or replaced system libraries.
3. Cleaning Up Dockerfiles
During local development, test manual setup steps inside a container. Running docker diff shows you the exact set of files created by package managers, helping you craft accurate COPY and RUN instructions for your Dockerfile.
Limitations of docker diff
- Volume Mount Exclusions:
docker diffinspects only the ephemeral container layer. Files written inside mounted volumes (-v /host/path:/container/path) ortmpfsmounts are explicitly excluded fromdocker diffoutput. - Performance Overhead on Massive Filesystems: Scanning containers that have written millions of tiny files can cause temporary CPU spikes on storage drivers.
Summary
docker diff is a simple yet powerful diagnostic command for auditing container filesystem state, detecting missing volume mounts, and triaging security incidents.