Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker: how to show the diffs between 2 images

Tags:

docker

I have a Dockerfile with a sequence of RUN instructions that execute "apt-get install"s; for example, a couple of lines:

RUN apt-get install -y tree RUN apt-get install -y git 

After having executed "docker build", if I then execute "docker images -a", I see the listing of all the base-child-child-.... images that were created during the build.

I'd like to see a list of all of the packages that were installed when the "apt-get install -y git" line was executed (including the dependent packages that may have also been installed, besides the git packages).

Note: I believe that the "docker diff" command shows the diffs between a container and the image from which it was started. Instead I'd like the diffs between 2 images (of the same lineage): the "tree" and "git" image IDs. Is this possible?

Thanks.

like image 311
jd. Avatar asked Jan 18 '14 05:01

jd.


People also ask

What is Docker diff command?

The command docker diff can be used to inspect the changes made to files or directories on a container's filesystem. Usage: docker diff CONTAINER. This docker diff command list the files and directories that are changed in a container᾿s filesystem from the time of container created.

Can you tell the differences between a docker image and layer?

Each layer is an image itself, just one without a human-assigned tag. They have auto-generated IDs though. Each layer stores the changes compared to the image it's based on. An image can consist of a single layer (that's often the case when the squash command was used).

How do I check the connection between two containers?

Check that the bridge network is running: You can check it's running by typing docker network ls . This should show the bridge network in the list. Start your containers: Start your containers as normal, with docker run . When you start each container, Docker will add it to the bridge network.

Can you combine 2 Docker images?

Docker doesn't do merges of the images, but there isn't anything stopping you combining the dockerfiles if available, and rolling into them into a fat image which you'd need to build.


2 Answers

Have a look at :

https://github.com/GoogleCloudPlatform/container-diff

This tool can diff local or remote docker images and can do so without requiring docker to be installed. It has file as well as package level "differs" (for example: apt, npm, and pip) so that you can more easily see the differences in packages that have changed between two docker images.

Disclaimer: I am a contributor to this project

like image 112
aaron-prindle Avatar answered Sep 19 '22 11:09

aaron-prindle


This one worked for me:

docker run -it e5cba87ecd29 bash -c 'find /path/to/files -type f | sort  | xargs -I{} sha512sum {}' > /tmp/dockerfiles.e5cba87ecd29.txt docker run -it b1d19fe1a941 bash -c 'find /path/to/files -type f | sort  | xargs -I{} sha512sum {}' > /tmp/dockerfiles.b1d19fe1a941.txt meld /tmp/dockerfiles* 

Where e5cba87ecd29 and b1d19fe1a941 are images I am interested in and /path/to/files is a directory which could be "/". It lists all files, sorts it and add hash to it just in case. And meld highlights all the differences.

like image 29
fallens4e Avatar answered Sep 16 '22 11:09

fallens4e