codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Follow publication

Docker: FROM scratch

How to build a minimalistic hello-world Docker image.

Changhui Xu
codeburst
Published in
5 min readJun 30, 2020

--

We know that Docker images are built up from a series of stacked layers that are themselves each a delta of the changes from the previous layer. For example, let’s consider the Dockerfile for the Docker image nginx:alpine:

The content of the Dockerfile above is excerpted from the docker-nginx repository (link). This Dockerfile contains instructions to build the nginx:alpine Docker image by adding a new writable layer (a.k.a. “container layer”) on top of a parent image (e.g., the alpine:3.11 image in line 1). The writable layer is usually where we write new files, modify existing files, and delete files, and this layer is the delta from its underlying layers.

Now the question is, what is the lowest, or bottom-most, layer of the Docker images? Or, in other words, how do we build the base images such as alpine (~ 5.6 MB) and busybox (~ 1.2 MB)?

To answer these questions, we can check the Git repositories for alpine (repo link) and busybox (repo link), and read their build scripts and Dockerfiles. For example, the following screenshot shows the Dockerfile for the busybox image.

In the Dockerfile above, line 1 instructs Docker to build the image starting from the scratch image. Line 2 adds a pre-built root filesystem (rootfs) on top of the scratch image. Note that the ADD busybox.tar.xz / command will extract the tar file to the destination / folder. (This is one of the differences between the ADD and COPY commands in Dockerfile instructions.) Line 3 sets up the default entry point and starts a shell for a…

--

--

Published in codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Written by Changhui Xu

Lead Application Developer. MBA. I write blogs about .NET, Angular, JavaScript/TypeScript, Docker, AWS, DDD, and many others.

No responses yet

Write a response