Comparing Container Versions with DockerSlim and Slim.AI

See differences between your original and slimmed images
Pieter van Noordennen
Jul 07, 2021

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 project and DockerSlim’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.
  2. An optimized version of a container on your desktop. We’ll use a “Hello World” Python/Flask 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, or watch the recorded livestream 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
    REPOSITORY              TAG     IMAGE ID        CREATED         SIZE
    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 portal.slim.dev 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. 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 channel.

Related Articles

5 Most Commonly Asked DockerSlim Questions

We enlisted DockerSlim expert and Slim.AI Developer Experience Engineer to dive into how container slimming works.

Primož Ajdišek

Technical Staff

Automatically reduce Docker container size using DockerSlim

REST Web Service example using Python/Flask

John Amaral

CEO

Automating DockerSlim in Your CICD Pipeline

Using GitHub Actions, you can refine container images automatically making them smaller, faster to load, and more secure by default – all without sacrificing any capabilities.

Nicolas Bohorquez

Contributor

Building DockerSlim into a Jenkins Pipeline

A step by step tutorial on building DockerSlim into your CI/CD pipeline.

Explore and analyze a Docker container with DockerSlim X-Ray

Understanding container composition

Martin Wimpress

Community

In the Media: DockerSlim and Slim.AI

Latest Mentions

Slim.AI and OSI: Why We Advocate for Open Source

Slim.AI continues its support of OSI and sponsors the OSI licensing API as a part of its ongoing advocacy for open source

Pieter van Noordennen

Growth

Slimming a Rails Application with DockerSlim

Dissect a simple Rails application container using DockerSlim to analyze, optimize, and deploy your product more quickly.

Theofanis Despoudis

Contributor

The DockerSlim Origin Story

How DockerSlim got its start at Docker's Global Hack Day, and the creation of Slim.AI.

Kyle Quest

CTO

What DockerSlim Users Get Out of Slim's SaaS Platform

Scaling Your Container Game

Martin Wimpress

Community

Building Apps Using Cloud Native Buildpacks

Getting started with this innovative technique

Vince Power

Contributor

Five Proven Ways to Debug a Container

When Things Just Are Not Working

Theofanis Despoudis

Contributor

Getting Started with Multi-Container Apps

Up your container game with Docker Compose

Nicholas Bohorquez

Contributor

Reducing Docker Image Size - Slimming vs Compressing

Know the difference

Pieter van Noordennen

Growth

Quick Start Guide

Slim Developer Platform Early Access

Meet DockerSlim's Compose Mode

Optimize a multi-tier app with a single command

Ian Juma

Technical Staff

What’s in your container?

Why Docker Layers matter for container optimization

Pieter van Noordennen

Growth

Creating a Container Pipeline with GitLab CI

Shipping containers the easy way

Nicolas Bohorquez

Contributor