Check For File Changes Inside a Docker Container

In this post, we will learn how to review which files have changed on a deployed Docker container.

Tracking file changes inside a running container can be very beneficial when troubleshooting applications or tracking changes.

Docker Diff

For the above reason, Docker has made the diff command available for us, as you will see shortly.

Let’s start with deploying a container called deploy01 using the following command.

docker run --name deploy01 -ti  python /bin/bash

After deploying the container, I will use a Python script inside the container. To check what has changed, I will run the following command.

docker container diff deploy01

In the below output, you will show what has changed and how using the following guidelines:

AA file or directory was added to the container.
DA file or directory was deleted from the container
CA file or directory was changed inside the container
Guidelines for changes
C /root
A /root/.bash_history
C /root/.python_history
C /usr
C /usr/local
C /usr/local/lib
C /usr/local/lib/python3.9
C /usr/local/lib/python3.9/encodings
C /usr/local/lib/python3.9/encodings/__pycache__
A /usr/local/lib/python3.9/encodings/__pycache__/__init__.cpython-39.pyc
A /usr/local/lib/python3.9/encodings/__pycache__/aliases.cpython-39.pyc
A /usr/local/lib/python3.9/encodings/__pycache__/latin_1.cpython-39.pyc
A /usr/local/lib/python3.9/encodings/__pycache__/utf_8.cpython-39.pyc
C /usr/local/lib/python3.9/__pycache__
A /usr/local/lib/python3.9/__pycache__/_bootlocale.cpython-39.pyc
A /usr/local/lib/python3.9/__pycache__/_collections_abc.cpython-39.pyc
A /usr/local/lib/python3.9/__pycache__/abc.cpython-39.pyc
A /usr/local/lib/python3.9/__pycache__/io.cpython-39.pyc
A /usr/local/lib/python3.9/__pycache__/os.cpython-39.pyc
A /usr/local/lib/python3.9/__pycache__/rlcompleter.cpython-39.pyc
A /usr/local/lib/python3.9/__pycache__/_sitebuiltins.cpython-39.pyc
A /usr/local/lib/python3.9/__pycache__/codecs.cpython-39.pyc
A /usr/local/lib/python3.9/__pycache__/genericpath.cpython-39.pyc
A /usr/local/lib/python3.9/__pycache__/posixpath.cpython-39.pyc
A /usr/local/lib/python3.9/__pycache__/site.cpython-39.pyc
A /usr/local/lib/python3.9/__pycache__/stat.cpython-39.pyc
A /