When I want to optimize the Dockerfile, I need to know the meaning of the base image tag. Like:
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 is the Python version, and the
stretch is the Linux distribution.
There are a few notes:
Debianrelease, the former means
Debian 9, the latter means
alpineis another Linux distribution
Debian 8but remove some extra files that are normally not necessary within containers: docker-slim
We all have heard the mainstream distribution, like
Centos. But as base images, they are very large to takes up a few hundred megabytes of space
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.
In the docker-slim,
docker-slim could convert a big
ubuntu image(400MB) to
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
PHP, they all have
slim-jessie as the base image tag. So maybe this is a good sign to use
How to choose base image
From this picture, The
alpine is widely used, and even larger than the other images occupancy rates combined.
- If the project already has a base image, I recommend keeping to use it.
- If the project is a new project, I recommend to consider the
alpinebase image. It’s can make the images extremely small.
- If you are using compiled languages, like Golang, just use
alpine, It uses the least number of dependencies(Some images even use
scratchas their base. This images is for the tool used by every one, so it’s need to control the size)
- If you are using Python, just use
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:
- The disk is very large in modern server
- The layer you need to pull in every round update is small, and you may not worry about the base image size
- Using Debian could be more stable
Docker hub Python image Docker hub Golang image Docker hub Node image