I usually use a Ubuntu or Arch Linux image but I found out recently that there is an OS called CoreOS specifically for docker containers.
As I am new to docker I am not sure which one would be the best base image to build my Dockerfile. It seems like a silly question but in case if I run lots of microservices on several containers, then the container should be as light as possible.
This is 982 MB per image, or *98.2%* of image size. In real-life situations, the 'shared' layer from the examples represents the image layers that seldom change (base image + top immutable layers).
The scratch image is the most minimal image in Docker. This is the base ancestor for all other images. The scratch image is actually empty. It doesn't contain any folders/files ...
Hello-World, the smallest image Hello-world is an official image provided by Docker, which is usually used to verify whether Docker has been installed successfully. As you can see from the above output, it only has 13.3KB! $ docker run hello-worldHello from Docker!
This really depends on your requirements:
FROM scratch
: if you are able to statically compile your application and don't need any other binaries (libraries, shells, or any other command period), then you are use the completely empty "scratch". You'll see this used as the starting point for the other base images, and it's also found in a lot of pre-compiled Go commands.
Busybox: I consider this less of a base image and more of a convenient utility container. You get a lot of common commands in a very small size. However what you don't get is the general package manager to easily install other components. Current size of this is under 1M.
Alpine: This is docker's take on a streamlined image and it does a good job and being small but also giving you a package manager. However that small size comes at a cost, things like glibc are not included. You will find that many of the official images are based on Alpine, so inside of the container ecosystem, this is a very popular option. Current size of this is around 2M before you start adding packages.
Debian, Ubuntu, and CentOS: These are less of the lightweight base images, each coming in around 50M give or take. But what they lose with size they gain with a large collection of packages you can pull from and lots of people that are testing, fixing bugs, and contributing to things upstream. They also come with a collection of libraries that some applications may expect to be preinstalled.
While that last option is a bit larger, keep in mind that base images should only be pushed over the wire and stored on disk once. After that, unless you change them, any images built on top of them only need to send the manifest that references layers in that base image and the docker engine will see that it already has those layers downloaded. And with the union fs, those layers never need to be copied even if you run 100 containers all pointing back to that image, they each use the same read-only layer on disk for all the image layers and write their changes to the their container specific RW layer.
Have a try to alpine linux
base image, it's really small(5M) and have has access to a package repository. We're using it to build our JDK base image in our production env and it's running good so far.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With