What's the lightest base image I can use to create a docker file?

I usually use ubuntu, arch linux image, but recently found out that there is an OS called coreOS specifically for docker containers. Since I am new to docker, I am not sure which one would be the best base image for building my docker file. This seems like a silly question, but in case I run many microservices on multiple containers, the container should be as lightweight as possible.

+3


source to share


2 answers


It really depends on your requirements:

  • FROM scratch

    : if you can statically compile your application and don't need any other binaries (libraries, wrappers or any other command period) then you are using a completely empty scratch. You will see that this is used as a starting point for other base images, and it also appears in many precompiled Go commands.

  • Busybox: I'm considering this less base image and more handy utility container. You get a lot of common commands in a very small size. What you don't get, however, is a generic package manager that installs other components easily. The current size is less than 1 M.

  • Alpine: This is a docker that uses a simplified image and it works well and is small, but it also provides a package manager. However, this small size is expensive, things like glibc are not included. You will find that many of the official images are based on Alpine, so this is a very popular option within the container ecosystem. The current size of this file is about 2 million before you start adding packages.

  • Debian, Ubuntu and CentOS: These are less light base images, each approaching 50M or yielding. But what they lose with the size they get, with a large collection of packages you can retrieve, and tons of people testing, fixing bugs and contributing to what's going up. They also come with a set of libraries that some applications may anticipate in advance.



While this latter option is a bit larger, keep in mind that base images only need to be pushed down the wire and stored on disk once. After that, if you don't change them, any images built on top of them will have to send a manifest that refers to the layers in that base image, and the docker engine will see that it is already loading those layers. And with fs merge these layers never need to be copied, even if you run 100 containers all pointing to this image, each one uses the same read-only level on disk for all image layers and writes their changes to their specific container RW layer.

+6


source


Try the alpine linux

base image, it is really small (5M) and has access to the package repository. We use it to build our base JDK image in our env project and it still works.



0


source







All Articles