Thursday, 17 August 2017

How to find differences between two docker images or containers.

Docker comes with a handy command called docker diff which allows you to find differences between the image and the container.

So if we make changes inside the container then we can find the difference from the image this is based on using the docker diff command.

But sometimes we might have to find differences between two running containers, in order to do this i found this helpful.

We can use the docker export command to export the filesystem of the container into a tarball and use our normal diff tools to compare.

This is how i did this:

Assume the image we are comparing is in our own docker registry docker.mysite.com:dev:0.25 and docker.mysite.com:dev:0.26 I would first create a container with the two images and then give the command

docker export dev025-instance -o dev05.tar

and

docker export dev026-instance -o dev06.tar

untar the files in separate folders and use an ide like PHPStorm to compare side by side.

For mac users there is a brew available to tap (https://github.com/moul/docker-diff) using

brew tap moul/moul

and then

brew install docker-diff

This does speed things up and you do not need to create containers etc, because docker-diff does that for you implicitly. However i felt it was easier with docker export commands due to large number of changes i was dealing with.

Docker diff works both with custom as well as official docker repos.


No comments:

Post a Comment