7. DevOps: How to track changes in a container

Docker-logo

In  continuation of my previous blog on “6. DevOps: How to work with interactive docker containers”, in this blog I would like to show some lab practice “How to track changes in a container”.

Tracking changes inside containers:

Now, let us see the container operations and tracking them.

Let’s launch a container in interactive mode, as we have done in previous session, we can use the below command.

$ sudo docker run -i -t ubuntu:16.04 /bin/bash 
=================>
vskumar@ubuntu:/var/log$ sudo docker run -i -t ubuntu:16.04 /bin/bash  
root@718636415a7f:/# ps
   PID TTY          TIME CMD
     1 pts/0    00:00:00 bash
     9 pts/0    00:00:00 ps
root@718636415a7f:/# ps -ef
UID         PID   PPID  C STIME TTY          TIME CMD
root          1      0  0 12:39 pts/0    00:00:00 /bin/bash
root         10      1  0 12:53 pts/0    00:00:00 ps -ef
root@718636415a7f:/# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@718636415a7f:/# 
======================>
Now, let us go to home directory:
========>
root@718636415a7f:/# pwd
/
root@718636415a7f:/# cd home
root@718636415a7f:/home# pwd
/home
root@718636415a7f:/home# ls
root@718636415a7f:/home# 
==============>
Now, as a standalone machine of this docker container, 
I want to create 4 text files using touch command as below:
==============>
root@718636415a7f:/home# ls
root@718636415a7f:/home# ls -l
total 0
root@718636415a7f:/home# touch {vsk1,vsk2,vsk3,vsk4}
root@718636415a7f:/home# ls -l
total 0
-rw-r--r-- 1 root root 0 Nov 25 12:57 vsk1
-rw-r--r-- 1 root root 0 Nov 25 12:57 vsk2
-rw-r--r-- 1 root root 0 Nov 25 12:57 vsk3
-rw-r--r-- 1 root root 0 Nov 25 12:57 vsk4
root@718636415a7f:/home# 
======================>

I am adding some text to each of them as below:

====================>

root@718636415a7f:/home# pwd

/home

root@718636415a7f:/home# echo ‘Testing vsk1’ > vsk1

root@718636415a7f:/home# ls -l

total 4

-rw-r–r– 1 root root 13 Nov 25 13:02 vsk1

-rw-r–r– 1 root root 0 Nov 25 12:57 vsk2

-rw-r–r– 1 root root 0 Nov 25 12:57 vsk3

-rw-r–r– 1 root root 0 Nov 25 12:57 vsk4

root@718636415a7f:/home# echo ‘Testing vsk2’ > vsk2

root@718636415a7f:/home# echo ‘Testing vsk3’ > vsk3

root@718636415a7f:/home# echo ‘NOT Testing vsk4’ > vsk4

root@718636415a7f:/home# ls -l

total 16

-rw-r–r– 1 root root 13 Nov 25 13:02 vsk1

-rw-r–r– 1 root root 13 Nov 25 13:02 vsk2

-rw-r–r– 1 root root 13 Nov 25 13:02 vsk3

-rw-r–r– 1 root root 17 Nov 25 13:02 vsk4

root@718636415a7f:/home#

=====================>

I have created 4 files and added some text into them.

Now, I want to execute a diff command on them:

==========================>

root@718636415a7f:/home# diff vsk1 vsk2

1c1

< Testing vsk1

> Testing vsk2

root@718636415a7f:/home# diff vsk2 vsk3

1c1

< Testing vsk2

> Testing vsk3

root@718636415a7f:/home# echo ‘NOT Testing vsk4’ > vsk1

root@718636415a7f:/home# diff vsk1 vsk4

root@718636415a7f:/home# diff vsk2 vsk4

1c1

< Testing vsk2

> NOT Testing vsk4

root@718636415a7f:/home#

===========================>

Now, I want to exit this container and go back to docker host.

I have detached it using exit.

And back to docker host.

Now, I want to use the diff command as below from host machine to the container:

===========================>

root@718636415a7f:/home# ls -l

total 16

-rw-r–r– 1 root root 17 Nov 25 13:05 vsk1

-rw-r–r– 1 root root 13 Nov 25 13:02 vsk2

-rw-r–r– 1 root root 13 Nov 25 13:02 vsk3

-rw-r–r– 1 root root 17 Nov 25 13:02 vsk4

root@718636415a7f:/home# exit

exit

vskumar@ubuntu:/var/log$ sudo docker diff 718636415a7f

[sudo] password for vskumar:

C /home

A /home/vsk1

A /home/vsk2

A /home/vsk3

A /home/vsk4

C /root

A /root/.bash_history

vskumar@ubuntu:/var/log$

=====================>

The 1st line ‘C /home’ shows; the home directory is modified by showing ‘C’ as changed.

The ‘A’ shows;  before each line denotes the file is added.

If you have a deleted file, it can show as ‘D’ before the file.

Also please let us note here on how docker engine picks up the image with the below priority;

When we work with an image and if we don’t specify that image name, then the latest image (recently generated) will be identified and used by the Docker Engine.

We can check the status of the containers as below using ps -a:

You can see a detailed output from this command from the below display:

==================================>

vskumar@ubuntu:/var/log$ ls

alternatives.log bootstrap.log dmesg fsck kern.log speech-dispatcher unattended-upgrades wtmp

apport.log btmp dpkg.log gpu-manager.log lastlog syslog upstart Xorg.0.log

apt cups faillog hp lightdm syslog.1 vmware Xorg.0.log.old

auth.log dist-upgrade fontconfig.log installer samba syslog.2.gz vmware-vmsvc.log

vskumar@ubuntu:/var/log$ sudo docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

cb1ff260d48e ubuntu “ls /usr/src” 3 minutes ago Exited (0) 3 minutes ago wonderful_hawking

b20691fd8fb5 ubuntu “ls /usr” 3 minutes ago Exited (0) 3 minutes ago friendly_mirzakhani

431ba4c53028 ubuntu “ls” 3 minutes ago Exited (0) 3 minutes ago affectionate_nobel

2c31684bb1f4 ubuntu “ls -la” 3 minutes ago Exited (0) 3 minutes ago zealous_meitner

fe2e3b449daf ubuntu “ls -la /home/.” 4 minutes ago Exited (0) 4 minutes ago dreamy_shirley

c44bdd05b94d ubuntu “ls -la home.” 4 minutes ago Exited (2) 4 minutes ago elastic_pasteur

8b8afa82859a ubuntu “ls -la” 4 minutes ago Exited (0) 4 minutes ago festive_panini

2811eb37af61 ubuntu “ls -la 604831dbce2a” 4 minutes ago Exited (2) 4 minutes ago jolly_swartz

604831dbce2a ubuntu:16.04 “/bin/bash” 8 minutes ago Exited (0) 6 minutes ago vibrant_ride

718636415a7f ubuntu:16.04 “/bin/bash” 45 minutes ago Exited (0) 18 minutes ago reverent_noyce

53a7751d4673 ubuntu:16.04 “/bin/bash” 2 hours ago Exited (0) 2 hours ago musing_chandrasekhar

32bc16b508d4 ubuntu “bash” 3 hours ago Exited (0) 3 hours ago eager_goldberg

1dd55efde43f hello-world “/hello” 3 hours ago Exited (0) 3 hours ago peaceful_pasteur

a744246ffb8e hello-world “/hello” 5 hours ago Exited (0) 5 hours ago naughty_wing

1ba71598b7b8 hello-world “/hello” 5 hours ago Exited (0) 5 hours ago musing_kare

vskumar@ubuntu:/var/log$

============================>

I would like to terminate the session at this point. In the next blog I would like to present “How to control and operate docker containers”.

Vcard-Shanthi Kumar V-v3

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s