Generating results
This is usually done within a minute.
Speed up your cloud infrastructure by optimizing the docker images - Docker | Kubernetes
One can work on docker in two ways, first by picking a docker image for their project from the Docker Hub or any other repository and pick any base image and build on top of it. When you build your docker image the image size can be very large and it can highly affect your environment in which you run as it will have to transfer a lot of data from one system to another to spin up the container. Generally, the time it takes to spin up a large docker image can happen in seconds but when the number of docker images increases then it will be a problem.and hence consumes a lot of your bandwidth and spin up time in the scalable infrastructure like Kubernetes (K8s), Docker Swarm, etc.
In this blog post, I’ll be discussing the small and widely used docker images like the alpine, slim, and debian and why image size of the docker matters. Let’s start off with the debian distro as the base image.
Debian Distros
Linux releases have code names like Bionic Beaver (Ubuntu 18.04), Tumbleweed (openSUSE 15), Buster (Debian 10.5). All the debian releases list can be found at https://wiki.debian.org/DebianReleases:
The following are Debian codename and that can be found in the docker project page and represents the base image of that project:
- Buster (Debian version 10) - At the time of writing this document, this is the stable release
- Stretch (Debian version 9)
- Jessie (Debian version 8)
The following pattern is used to identify the above distros:
- ::-buster
- Ex: python:3.8-buster
- :-slim-buster
- Ex: python:3.8-slim-buster
- :-stretch
- Ex: python:3.8-stretch
- :-jessie
- Ex: python:3.8-jessie
Alpine
One of the simplest, smallest, lightweight, and secure linux images for docker. The image size is around 6MB. The pattern to identify the alpine distro is ::-alpine.
Ex: python:3.6-alpine
The following are the pros and cons of using alpine as base docker image:
Pros:
- Small size of the docker image
- Fast integration and deployment
- It runs on very little resources and hence it is secure.
Cons:
- Uses musl libc instead of glibc. Some python packages build the project that requires build-essential, and cmake to be installed and these libraries mostly use glibc, so it is harder to compile packages like Couchbase Python SDK, sklearn, tensorflow, etc. on alpine using pip.
Slim
It installs only the minimal packages needed to run the project. It uses the pattern :-slim. The image size of python:3.6-slim is around 111MB at the time of writing this blog post.
Why does image size matter?
While working on the docker image size does matter because it gives you the following advantages when the image size is small:
- Saves network latency as docker images are transferred from one system to another
- Saves storage space as it has less instructions to store.
- Faster spinning up of containers. Some docker schedulers like Kubernetes, Docker Swarm, etc. spins up and down a lot of containers over a pool of nodes, so with the smaller image size these schedulers can spin up containers at a rapid rate.
- When using a small docker image like alpine we also get a lot of security as there are very few processes running in the background.
- Oftentimes, when spinning up the containers, the base image of these containers run a lot of processes that aren’t required for our application or system and by using the alpine image we can run those processes that we need.
- Smaller image size speeds up the development and integration process as smaller the Docker image size the faster builds and faster deployment