
The FROM keyword
Every Dockerfile starts with the FROM keyword. With it, we define which base image we want to start building our custom image from. If we want to build starting with CentOS 7, for example, we would have the following line in the Dockerfile:
FROM centos:7
On Docker Hub, there are curated or official images for all major Linux distros, as well as for all important development frameworks or languages, such as Python, Node.js, Ruby, Go, and many more. Depending on our needs, we should select the most appropriate base image.
For example, if I want to containerize a Python 3.7 application, I might want to select the relevant official python:3.7 image.
If we really want to start from scratch, we can also use the following statement:
FROM scratch
This is useful in the context of building super-minimal images that only—for example—contain a single binary: the actual statically linked executable, such as Hello-World. The scratch image is literally an empty base image.
FROM scratch is a no-op in the Dockerfile, and as such does not generate a layer in the resulting container image.