The Slim.AI Blog

Comparing Container Versions with DockerSlim and Slim.AI

See differences between your original and slimmed images

Pieter van Noordennen

Often, developers see Docker containers as an “opaque box of goodness,” and that’s not always a good thing.

Knowing what's changed from one container version to another can be cumbersome and difficult, and it's increasingly difficult to track how containers change throughout their lifecycle.

Open source tools, including Alex Goodman’s Dive (opens new window) project and DockerSlim (opens new window)’s XRay function, can provide insights but generally are regarded as expert-level tools, with all the benefits and drawbacks of open-source.

The Slim Developer Platform provides an easy to use web interface for seeing differences between two container versions. If you’ve used DockerSlim to optimize a container — or created a production-ready container some other way — and are curious to know what’s changed from your original container, this tutorial will show you how to do that.

# To complete this tutorial, you’ll need:

  1. A Slim.AI Early Access Account. Sign in here (opens new window).
  2. An optimized version of a container on your desktop. We’ll use a “Hello World” Python/Flask (opens new window) example we minified using DockerSlim.
  3. A container registry account. We’ll use Docker Hub for this example, but AWS ECR or Google Container Registry will also work.
  4. (optional) DockerSlim installed on your desktop.

Our goal is to optimize a container, send it to a registry, and then bring that container into the Slim Developer Portal to see what’s changed using the platform’s Explorer and Diff tools.

Let’s get started.

# 1. Optimize and tag the image

For this example, we’ll use the simple Python-Flask example we used in our Container of the Week series on Twitch. You can read a description and download code samples in our slim-containers GitHub repo (opens new window), or watch the recorded livestream (opens new window) for more info.

This basic example has two versions of the image, one that is based on the original and one that was slimmed using the DockerSlim build command. I have both of these images on my desktop and can see them using the docker images command.

    $ docker images
    cotw-python-flask 		latest 	75a3a2837473 	23 hours ago 	895MB
    cotw-python-flask.slim 	latest 	8c6dc985ee9f 	3 minutes ago 	47.8MB

Note that we’ve tested these images to make sure they’re working properly and functionally equivalent.

In order to compare the images using the Slim Developer Platform, I’m going to make them two different versions of the same image using tags. We’ll create carbon copy of the slim image and rename it cotw-python-flask:slim.

    $ docker tag cotw-python-flask.slim cotw-python-flask:slim

# 2. Push to Docker Hub

Since we need the image to exist in one of our registries in order to access it later, we’ll need to push it to a cloud-based container registry. We'll use Docker Hub's free, public account, though Slim.AI also supports private Docker Hub registires as well as AWS ECR and Google Container Registry.

Be careful! Pushing images to the public Docker Hub registry will make them available on the public internet. Please check your compliance standards, security protocols, and general common sense before doing this, or use a private instance on ECR or GCR if you have access to one.

You’ll have to authenticate your Docker command line interface to connect to Docker Hub if you haven’t already. Then, just push both images to Docker Hub.

    $ docker push cotw-python-flask:latest
    $ docker push cotw-python-flask:slim

Here again, latest is the original large image, and slim is the optimized image. We’re now ready to access them via the Slim.AI portal. The images will be available, unless specified otherwise, with the format myusername/myimagename:tag.

# 3. Visit the Slim.AI portal and connect to Docker Hub

Visit (opens new window)and login using your preferred method (GitHub, GitLab, or Bitbucket). Navigate to the Connectors screen in the global navigation.

Since we are connecting to Docker Hub, click on the Connect link in the Docker Hub connection tile.

Create a secure connection to your Docker Hub repo by visiting Settings > Access Tokens (opens new window). You’ll need to be logged into the same Docker Hub account where you originally pushed your images.

Click New Access Token and give the access token a name that you can reference later. Click Create and then copy the token to your clipboard.

Docker Hub Create Access Token modal screenshot

Docker Hub Create Access Token modal screenshot

Back in the Slim.AI Portal, paste the access token into the access token field in the UI and fill in the name of your Docker Hub registry. Optionally, you can name this connection, which is useful if you plan to connect multiple registries on the same platform. We'll call this one "Slim Dev".

# 4. Scan the image in Slim.AI

Screenshot of Connected Registries screen

Screenshot of Connected Registries screen

Once the registry is connected and authenticated, you can scan images in it by either searching for your registry name or navigating back to the Home screen and clicking on the Connected Registries tab.

Simply click the tag you want to view to scan it. Start with your original image (in our example, the latest tag). On the image detail page, you’ll find container metadata, including the user, open ports, and available shells. You’ll also be able to see files, instructions, and layers in the Explorer tab.

# 5. Compare versions using Diff

In the Overview tab, scroll down to the Available Versions section to see different versions of your container. Since we updated the image to have :latest and :slim tags, you should see both available here.

Screenshot of Compare Versions using Diff

To see the differences between the containers, click the Diff icon listed in the :slim container row. From the next selector screen, be sure to be comparing Latest to the Slim version, so we can see which files were removed during the optimization process.

screenshot of compare versions selector

screenshot of compare versions selector

You'll be brought to a new explorer-esque interface that shows you the differences between the two containers.

# File View

screenshot of File View

In the file view, you can see removed files (listed in red), modded files (listed in gray), and added files (listed in green). Since we are comparing the slim version to the latest version, we are seeing everything that DockerSlim removed from the original image to create the slimmed version.

For instance, here we can see that DockerSlim removed the requirements.txt file, since it is no longer needed in the final version of the container.

You can choose to see images in a Tree view (showing which files belong in which folders) or Flat view to simply see a list of files. Clicking on a file will show metadata about the file. (Full file text and file diff capabilities are coming in future releases.)

In the sub-navigation above the file viewer, you can filter your results in various ways. The Objects filter lets you narrow your output to just Additions, Deletions, or Modifications, or filter to binaries or utf-8 (text) files. While binary files have only metadata available, future releases will allow you to see the contents of text files, along with any modifications.

You can also adjust the metadata shown in the file list with the Columns selector.

Finally, the search box allows you to do a plain text search for filenames if you are curious about what happened to a specific file or library. This can be useful when debugging a container build, as DockerSlim allows you to manually specify dependency inclusions using the --include-file and include-file-path flags.

# Coming Soon

Stay tuned as we release more ways to optimize your container workflows. We’ll be releasing several updates to our Diff and Collections features in coming months, in addition to working on new integrations with various container registries and other DevOps platforms.

Have a feature or integration idea? Let us know in the Slim.AI Community Discord (opens new window) channel.

Related Articles

See All Articles