For all the Dockerfiles I've come across thus (which admittedly is not many), all of them have used a FROM
clause to base off an existing image, even if it's FROM scratch
.
Is this clause required? Is it possible to have a Dockerfile with no FROM
clause? Will this container created thus be able to do anything?
EDIT
I read
A Dockerfile with no FROM directive has no parent image, and is called a base image.
https://docs.docker.com/glossary/?term=parent%20image
But I think this may be an error.
Yes, it is. It defines the layers on which the image you are building is based on. If you want to start an image from scratch docker offers an image called scratch
The documentation also says:
also
Refer to base images documentation
Short answer is yes, the FROM clause is required. But it's easier to come to this conclusion if you think of the image building process a bit.
Dockerfile is just a way to describe a sequence of commands to be executed by Docker build subsystem to create an image. And an image is just a bunch of regular files, most notably, user land files of a particular Linux distribution, but possibly with some extra files on top of it. Every Docker image is based on the parent image and adds its own files to the parent's set. Every image has to start FROM something, i.e. specify its parent. And the parent of all parents is a
scratch
image defined asnoop
, i.e. an empty set of files.Take a look at
busybox
image:It starts from scratch, i.e. an empty set of files, and adds (i.e. copies) to this set a bunch of files from
busybox.tar.xz
archive.Now, if you want to create your own image, you can start from
busybox
image and describe what files (and how) you are going to add:But every time a new image has to start FROM something.
Based on the official documentation it's required:
https://docs.docker.com/engine/reference/builder/#from