Tracking changes inside containers

In the previous section, we demonstrated how to craft a container taking ubuntu as a base image, and then running some basic commands, such as detaching and attaching the containers. In that process, we also exposed you to the docker ps subcommand, which provides the basic container management functionality. In this section, we will demonstrate how we can effectively track the changes that we introduced in our container and compare it with the image from which we launched the container. Let's launch a container in interactive mode, as in the previous section:

$ sudo docker run -i -t ubuntu:16.04 /bin/bash  

Let's change the directory to /home, as shown here:

root@d5ad60f174d3:/# cd /home  

Now, we can create three empty files using the touch command, as follows. The first ls -l command will show that there are no files in the directory and the second ls -l command will show that there are three empty files:

root@d5ad60f174d3:/home# ls -l
total 0
root@d5ad60f174d3:/home# touch {abc,cde,fgh}
root@d5ad60f174d3:/home# ls -l
total 0
-rw-r--r-- 1 root root 0 Sep 29 10:54 abc
-rw-r--r-- 1 root root 0 Sep 29 10:54 cde
-rw-r--r-- 1 root root 0 Sep 29 10:54 fgh
root@d5ad60f174d3:/home#

The Docker Engine elegantly manages its filesystem and it allows us to inspect a container filesystem using the docker diff subcommand. In order to inspect the container filesystem, we can either detach it from the container or use another Terminal of our Docker host and then issue the docker diff subcommand. Since we know that any ubuntu container has its hostname, which is a part of its prompt, and it is also the container's ID, we can directly run the docker diff subcommand using the container ID that is taken from the prompt, as shown here:

$ sudo docker diff d5ad60f174d3  

In the given example, the docker diff subcommand will generate four lines, as shown here:

C /home
A /home/abc
A /home/cde
A /home/fgh

The preceding output indicates that the /home directory has been modified, which has been denoted by C, and the /home/abc, /home/cde, and /home/fgh files have been added, and these are denoted by A. In addition, D denotes deletion. Since we have not deleted any files, it is not in our sample output.

When we work with an image and if we don't specify that image through an appropriate identity (say, a new name), then the latest image (recently generated) will always be identified and used by the Docker Engine.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset