The Docker diff command
docker diff This command is used to display changes in a Docker container's filesystem. It shows all modifications that have occurred since the container was created, including files or directories that were added, deleted, or modified.
docker diff This command is very useful for debugging and understanding filesystem changes in a container.
Syntax
docker diff CONTAINER
CONTAINER: The container's name or ID.
docker diff The command's output contains the following three types of changes:
A: indicates a newly added file or directory.D: indicates a deleted file or directory.C: indicates a modified file or directory.
View a container's filesystem changes
docker diff my_container
Display the filesystem changes of the container named my_container.
Example
Start a container and modify the filesystem:
docker run -d --name my_container ubuntu bash -c "echo 'Hello, Docker!' > /hello.txt && sleep 3600"
View the container's filesystem changes:
docker diff my_container
Example output:
A /hello.txt
This output indicates that the /hello.txt file was added to the container filesystem.
Delete a file in the container:
docker exec my_container rm /hello.txt
View the container's filesystem changes again:
docker diff my_container
Example output:
D /hello.txt
This output indicates that the /hello.txt file was deleted from the container filesystem.
Notes
docker diffThe command only shows filesystem changes in the container; it does not show other state information inside the container (such as running processes).- The output may change continuously as the container's filesystem changes, so it should be viewed promptly when needed.
docker diff This command is a powerful tool for displaying changes to a Docker container's filesystem. By using it, users can easily view and understand the filesystem changes made to a container since its creation, helping with debugging, auditing, and analyzing container behavior.
Docker Command Reference