简体   繁体   中英

Docker difference between two containers

How do I find the difference between two running containers using Docker client? I have an image running as multiple instances and later I have changed/installed new packages in the instances and lost track. Is there a way I can find the differences between these running containers?

You are looking for the docker diff command which lists changes made on a container filesystem since it was created.

Take this example in which a new container named so-26230214 is created, then the file /tmp/foo.txt is added and finally /etc/default/ntpdate removed:

$ docker run -it --name so-26230214 base bash -il
root@b33340ce7b9f:/# echo "foo" > /tmp/foo.txt
root@b33340ce7b9f:/# rm /etc/default/ntpdate
root@b33340ce7b9f:/# logout

The docker diff command prints out:

$ docker diff so-26230214
C /etc
C /etc/default
D /etc/default/ntpdate
C /root
A /root/.bash_history
C /tmp
A /tmp/foo.txt

detailling what files were C hanged, A dded or D eleted.

If you need details about what changed in those files, then you have no other choice than exporting the container filesystem with docker export or individual files with docker cp and examine them.

Note that docker export and docker cp will only show you files which are part of the container file system, as a result those commands won't give you access to files in volumes .

you must inspect container

docker inspect CONTAINER_1
docker inspect CONTAINER_2

find the fragment for each one

"Id": "cc502eeb69968c9b80c029f8124333d725ee124db4357de69786bc9bdf3a8088",

then with the tow ID you can compare the folders

/var/lib/docker/aufs/mnt/CONTAINER_1 vs /var/lib/docker/aufs/mnt/CONTAINER_2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM