Docker: Visualizing image hierarchy and container dependency using dockviz

The Docker console commands for listing and viewing containers and images (ps, images, history, inspect) provides a wealth of information, but when you are managing hundreds of containers, a graph view of the container inventory and their dependencies can be critical for operations.

Dockviz can help you visualize your containers and images by creating an PNG image representing the container links and image lineage.

I’ve made a few changes to the original project to fix issues with newer versions of docker, so I’ve repackaged Nate’s images.


If you have not installed Docker on Ubuntu, read my article here first.

Then, in order to render the container and image information as a PNG image you will need the “graphviz” package on the host system.  This can be installed like:

$ sudo apt-get install graphviz -y

Create alias

In order to make invocation easier (instead of typing a long command every time), create an alias for running the dockviz container.

If you are using a local unix socket to connect to the Docker daemon:

$ alias dockviz="sudo docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock fabianlee/dockviz"

And if you are using TCP to the Docker daemon:

$ alias dockviz="sudo docker run -it -e DOCKER_HOST='tcp://' fabianlee/dockviz"

Visualize Image History

Let’s spin up a quick sample,  then view an image history:

# quick docker run
$ sudo docker run docker/whalesay cowsay hello

# console - command to show images
$ sudo docker images

# console - show lineage of whalesay container
$ sudo docker history $(docker images docker/whalesay -q)

# use dockviz to generate picture of image history
$ sudo dockviz images -d | dot -Tpng -o images.png

If you have a lot of docker images, this picture can be very wide, so I’ll just cut out the portion relevant to the docker/whalesay image.

As you can see on the right, the generated graph essentially shows the same information as “docker history”, with each image layer and its size visible.

The <missing> tag is not an error, ever since Docker 1.10 and content addressability, this value is empty.  That is the reason I added the bash command and size to the graph node as an identifier.

Visualize Container Dependencies

In order to test dockerviz, you can just run it on the containers and images you already have loaded and running on your system.

$ dockviz containers -d -r | dot -Tpng -o /Documents/containers.png

But if you need a smoke test, we can pretty easily create a set of docker containers that are linked together.

On, there is an example application that uses a single MongoDB backend, with a Python Flask web application as the front end for end user’s browsers.  I have modified that example slightly so that you have two web front ends, both hitting the same MongoDB database.

Below are the instructions for bringing up this set of hosts.  If you don’t have docker-compose installed, you can read my article here.

$ sudo apt-get install git -y
$ git clone
$ cd flask_compose_sample
$ docker-compose up

This will take a minute the first time you run it because the various images have to be downloaded.  Now, when we run dockviz to show us the containers (-r switch means only those running):

$ dockviz containers -d -r | dot -Tpng -o /Documents/containers.png

Open “containers.png”, and as you can see below we have a picture of our dockviz container running on the left, and then we have a single MongoDB instance that both Python Flask web containers are dependent upon.


When you are running hundreds of containers, having a picture of these dependencies is invaluable.  This is the type of information that can help when troubleshooting microservices that have a web of dependencies, or when calculating the risk of a major upgrade.