Reviewing filesystem changes
In this lab, we will learn how to review filesystem changes made inside a Docker container. Docker provides a command to list all changes to the filesystem, including added, changed, or deleted files and directories.
When you read a file from a union filesystem, that file will be read from the topmost layer where it exists. If a file was not created or changed on the top layer, the read will fall through the layers until it reaches a layer where that file does exist. Here is a simple example:
In this illustration, files are added, changed, deleted, and added again over a range of three layers.
Task
- Create a container and add a new file and review changes
- Create another container and delete an existing file and review changes
- Create yet another container and change an existing file and review changes
- Clean up our workspace
Steps
Follow these steps to complete the task:
Create a container and add a new file:
Create another container and delete an existing file:
Review the filesystem changes:
docker container diff tweak-d
This command lists all the changes made to the filesystem of the tweak-d container. You should see:
Expected Output:
Command:
docker container run --name tweak-c busybox:latest touch /bin/vi
This command runs a new container named tweak-c from the busybox:latest image and updates the modification time of the file /bin/vi.
Review the filesystem changes:
docker container diff tweak-c
This command lists all the changes made to the filesystem of the tweak-c container. You should see:
This indicates that the directories /bin and /bin/busybox were changed.
Clean up our workspace by removing the containers:
docker container rm -vf tweak-a
docker container rm -vf tweak-d
docker container rm -vf tweak-c
These commands forcefully remove the tweak-a, tweak-d, and tweak-c containers, cleaning up our workspace.
Explanation of docker container diff Output
Lines that start with an A indicate files that were added.
Lines that start with a C indicate files that were changed.
Lines that start with a D indicate files that were deleted.
By following these steps, you'll be able to track and understand filesystem changes within Docker containers. This is particularly useful for debugging and for ensuring that your containerized applications behave as expected.
#/Commands Summary
Create a container and add a new file:
docker container run --name tweak-a busybox:latest touch /HelloWorld
#Review the filesystem changes:
docker container diff tweak-a
#Create another container and delete an existing file:
docker container run --name tweak-d busybox:latest rm /bin/vi
#Review the filesystem changes:
docker container diff tweak-d
#Create yet another container and change an existing file:
docker container run --name tweak-c busybox:latest touch /bin/vi
#Review the filesystem changes:
docker container diff tweak-c
#Clean up your workspace:
docker container rm -vf tweak-a
docker container rm -vf tweak-d
docker container rm -vf tweak-c

SOCIAL SHARE CARD GENERATOR