Skip to content

Instantly share code, notes, and snippets.

@rheinwein
Forked from argvader/imagelayers.md
Last active August 29, 2015 14:20
Show Gist options
  • Save rheinwein/14ed0f7abaeee38e2612 to your computer and use it in GitHub Desktop.
Save rheinwein/14ed0f7abaeee38e2612 to your computer and use it in GitHub Desktop.

ImageLayers.io is a new project from the team at CenturyLink Labs. This utility provides a browser-based visualization of user-specified Docker Images and their layers. This visualization provides key information on the composition of a Docker Image and any commonalities between them. ImageLayers.io allows Docker users to easily discover best practices for image construction, and aid in determining which images are most appropriate for their specific use cases.

##What are Layers? Docker uses a union filesystem for managing images. Each layer of an image is the result of some action taken during the build. This could be installing a package, copying files from a local or remote source, or setting an environment variable. Each action creates a new layer in the filesystem; layers reference their parents and are cached, so they may be used as a part of an entirely different image. ImageLayers will show you these relationships as a tree.

There is a direct correlation between your Dockerfile and the number of layers in your image. Docker offers some advice on Dockerfile best practices, and the team at CenturyLink Labs has also done work around optimizing Docker images.

##Creating Smarter Docker Images The layered filesystem is similar to a tree, and Docker is smart enough to branch from any layer if it sees the same work being done. For this reason, it's possible to consolidate work in order to optimize your images. There are two basic strategies for optimizing your Docker images: chaining commands and using smart base images.

###Chaining Commands to reduce the number of layers

Here's a sample Dockerfile that pulls down a base image and installs a package.

FROM debian:wheezy
WORKDIR /tmp

RUN wget -nv
RUN tar -xvf someutility-v1.0.0.tar.gz
RUN mv /tmp/someutility-v1.0.0/someutil /usr/bin/someutil
RUN rm -rf /tmp/someutility-v1.0.0
RUN rm /tmp/someutility-v1.0.0.tar.gz

Because there is a 1-to-1 correlated between the Dockerfile and the layers in the image, this image would have many layers. A new layer is created for each of the RUN commands.

Since each of the RUN commands above is related to the same package, we can chain them together and execute all of the commands on the same layers. That looks like this:

FROM debian:wheezy
WORKDIR /tmp

RUN wget -nv && tar -xvf someutility-v1.0.0.tar.gz \
  && mv /tmp/someutility-v1.0.0/someutil /usr/bin/someutil \
  && rm -rf /tmp/someutility-v1.0.0 \
  && rm /tmp/someutility-v1.0.0.tar.gz

The resulting image has fewer layers and therefore takes up less space than the first example.

ImageLayers lets you see each layer and its instruction more readily, making it easier for you to identify resource-sucking parts of your Dockerfile. For example, the analysis of the wordpress:latest image shows several run commands which could be concatenated using the technique above.

###Extracting shared work to a base image (image of shared layers) Using images with shared layers within your application will reduce download times and the overall filesystem size. A layer is only downloaded once regardless if many images require it. Therefore, choosing a good base image for your application can be a performance boon. Using ImageLayers to investigate images on the DockerHub before they are downloaded is a quick way to find which layers may be shared. Within ImageLayers, a shared layer spans the image columns so it is easy to identify which images a layer may have in common. The more layers in common, the fewer requests are required to download the images, leading to better performance for your application.

###ImageLayers Badge

Don't be the last image on the Docker Hub to have an ImageLayers badge! Use the 'Get an Embed Badge' feature to create an html link or a markdown fragment which can be embedded into a document.

ImageLayers was created to provide visual insight into the way an individual is created and how many images can share layers. This information can be used to understand how the Docker unified file system behaves or fine tune an application composed of many images. Create an analysis of some of your favorite images and share the url with your friends.

@argvader
Copy link

argvader commented May 5, 2015

ImageLayers was created to provide visual insight into the way an individual is created and how many images can share layers.

Add image? -- individual image is create

@argvader
Copy link

argvader commented May 5, 2015

I had a place holder for an image on the extracting shared work - we can either clip one or remove that placeholder

@argvader
Copy link

argvader commented May 5, 2015

i think Ross wanted all imagelayer.io to be links

@argvader
Copy link

argvader commented May 5, 2015

Even the Docker Hub sentence?? i know it was mine but prolly needs some help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment