Docker Tutorial
Docker Installation
How to use Docker
Docker Instance
Docker Container Lifecycle Command
Docker Container Operation Command
Docker Container rootfs Command
Docker Mirror Repository Command
Docker Local Image Management Command
Docker info|version Command
The docker diff
command allows you to inspect the changes made to a container's filesystem compared to its base image. This can be useful for understanding what modifications have occurred within the container, such as added, deleted, or modified files and directories. In this tutorial, we'll cover the basics of using the docker diff
command.
Syntax:
docker diff CONTAINER
CONTAINER
: The name or ID of the container you want to inspect.Example:
Run a container and make some changes:
docker run -it --name my-container ubuntu /bin/bash
Inside the container, create a new file, modify an existing file, and delete a file:
touch new-file.txt echo "modified" > /etc/hostname rm /etc/issue exit
Inspect the changes made to the container's filesystem:
docker diff my-container
This command will display a list of changes made to the container's filesystem. The output will show added (A), deleted (D), or modified (C) files and directories with their respective paths:
C /etc A /new-file.txt C /etc/hostname D /etc/issue
In this example, we can see that a new file (new-file.txt
) has been added, an existing file (/etc/hostname
) has been modified, and a file (/etc/issue
) has been deleted.
This tutorial should give you a basic understanding of how to use the docker diff
command to inspect changes made to a container's filesystem compared to its base image. This can be helpful for understanding what modifications have occurred within the container.
How to Use Docker Diff Command:
docker diff
displays changes to files in the container's filesystem.docker diff
:docker diff [OPTIONS] CONTAINER
Inspecting Changes with Docker Diff:
docker diff
to examine filesystem changes in a running or stopped container.docker diff my_container
Viewing File Changes in Docker Containers:
docker diff
provides a list of added, modified, or deleted files in the container filesystem.docker diff my_container
Comparing Container Filesystem Before and After Changes:
docker diff
to compare filesystem states before and after specific operations.docker run -d --name my_container nginx:latest # Make changes inside the container docker diff my_container
Monitoring Container Changes with Docker Diff:
docker diff
to monitor container filesystem changes for security or auditing purposes.watch docker diff my_container
Automating Docker Container Change Detection:
docker diff
into scripts or monitoring tools for automated change detection.docker diff
in a script:changes=$(docker diff my_container)
Troubleshooting with Docker Diff:
docker diff
can assist in identifying issues by revealing unexpected filesystem modifications.docker diff
:docker diff my_container