Millet Porridge

English version of https://corvo.myseu.cn

0%

Docker base image tag meaning and selection

When I want to optimize the Dockerfile, I need to know the meaning of the base image tag. Like: 3.8.0a4-stretch, 3.7.3-alpine3.8, 2.7.16-slim-jessie. I do some research, and make a summary of the meaning of the base image tag, and I’ll give you advice about choosing the proper base image.

The Linux distribution

When we use Python base images, like 3.8.0a4-stretch, The 3.8.0a4 is the Python version, and the stretch is the Linux distribution.

There are a few notes:

  1. stretch and jessie is Debian release, the former means Debian 9, the latter means Debian 8
  2. alpine is another Linux distribution
  3. slim-jessie means Debian 8 but remove some extra files that are normally not necessary within containers: docker-slim

Distribution details

We all have heard the mainstream distribution, like Debian, Ubuntu, Centos. But as base images, they are very large to takes up a few hundred megabytes of space

Alpine

alpine linux is much smaller than most distribution base images (~5MB), which uses musl libc and BusyBox. It also has their own package managers, better than some images just use busybox. It’s a good choice to use it as a base images.

Please be noted that:

The main caveat to note is that it does use musl libc instead of glibc and friends, so software will often run into issues depending on the depth of their libc requirements/assumptions.

docker-slim

In the docker-slim, docker-slim could convert a big ubuntu image(400MB) to 14MB.

This image does not contain the common packages contained in the default tag and only contains the minimal packages needed to run python. Unless you are working in an environment where only the python image will be deployed and you have space constraints, we highly recommend using the default image of this repository.

I noticed that the official base images like Python, Node, OpenJDK, PHP, they all have slim-stretch or slim-jessie as the base image tag. So maybe this is a good sign to use Debian.

How to choose base image

A survey

From this picture, The alpine is widely used, and even larger than the other images occupancy rates combined.

My advice

  1. If the project already has a base image, I recommend keeping to use it.
  2. If the project is a new project, I recommend to consider the alpine base image. It’s can make the images extremely small.
  3. If you are using compiled languages, like Golang, just use alpine, It uses the least number of dependencies(Some images even use scratch as their base. This images is for the tool used by every one, so it’s need to control the size)
  4. If you are using Python, just use stretch and jessie, not need to use slim. Sometimes, you may even need to install some dependencies using gcc. The size of the whole images will inevitably expand

Personally, I’d like to use Debian as the base image in production:

  1. The disk is very large in modern server
  2. The layer you need to pull in every round update is small, and you may not worry about the base image size
  3. Using Debian could be more stable

Reference

Docker hub Python image Docker hub Golang image Docker hub Node image