How to use docker diff

When you're working with Docker containers, it's helpful to know what changes have been made inside them. That's where the docker diff
command comes in handy. It lets you see what files or directories have been added, deleted, or changed since the container was first created.
The docker diff
command is pretty straightforward to use. You just need to specify the container you want to check. You can use the container's full ID, a shortened version of the ID, or even the name you gave the container when you started it with docker run --name
.
Here's how the command looks:
docker diff CONTAINER
When you run this command, Docker will show you a list of changes. Each change is marked with a letter that tells you what happened:
- A: This means a file or directory was added.
- D: This means a file or directory was deleted.
- C: This means a file or directory was changed.
Let's look at an example to see how this works in practice. Imagine you've got an nginx
container running, and you want to see what's changed inside it. You'd run a command like this:
docker diff 1fdfd1f54c1b
The output might look something like this:
C /dev
C /dev/console
C /dev/core
C /dev/stdout
C /dev/fd
C /dev/ptmx
C /dev/stderr
C /dev/stdin
C /run
A /run/nginx.pid
C /var/lib/nginx/tmp
A /var/lib/nginx/tmp/client_body
A /var/lib/nginx/tmp/fastcgi
A /var/lib/nginx/tmp/proxy
A /var/lib/nginx/tmp/scgi
A /var/lib/nginx/tmp/uwsgi
C /var/log/nginx
A /var/log/nginx/access.log
A /var/log/nginx/error.log
In this example, you can see that several files and directories have been changed (C
), and some new ones have been added (A
). For instance, /run/nginx.pid
was added, which is the process ID file for the nginx
server. Also, new log files like /var/log/nginx/access.log
and /var/log/nginx/error.log
were created.
Using docker diff
is a great way to keep track of what's happening inside your containers. It helps you understand how your applications are behaving and what files they're using or modifying. This can be really useful for debugging or just keeping an eye on things.