The FROM instruction

The FROM instruction is the most important one and is the first valid instruction of a Dockerfile. It sets the base image for the build process. Subsequent instructions will use this base image and build on top of it. The Docker build system lets you flexibly use the images built by anyone. You can also extend them by adding more precise and practical features. By default, the Docker build system looks for the images in the Docker host. However, if the image is not found in the Docker host, then the Docker build system will pull the image from the publicly available Docker Hub Registry. The Docker build system will return an error if it cannot find the specified image in the Docker host and the Docker Hub Registry.

The FROM instruction has the following syntax:

FROM <image>[:<tag>|@<digest>] 

In the preceding code statement, note the following:

  • <image>: This is the name of the image that will be used as the base image.
  • <tag> or <digest>: Both <tag> and <digest> are optional attributes and you can qualify a particular Docker image version using either a tag attribute or a digest attribute. The latest tag is assumed by default if both tag and digest are not present.

Here is an example of the FROM instruction with the centos image name:

FROM centos 

In the preceding example, the Docker build system will implicitly default to the latest tag because neither a tag nor a digest is explicitly added to the image name. Here is another example of the FROM instruction with the ubuntu image name and the 16.04 tag qualifier:

FROM ubuntu:16.04 

Next is a classic example of the FROM instruction with the ubuntu image name and the digest qualifier:

FROM ubuntu@sha256:8e2324f2288c26e1393b63e680ee7844202391414dbd48497e9a4fd997cd3cbf 

Docker allows multiple FROM instructions in a single Dockerfile in order to create multiple images. The Docker build system will pull all the images specified in the FROM instruction. Docker does not provide any mechanism for naming the individual images that are generated with the help of multiple FROM instructions. We strongly discourage using multiple FROM instructions in a single Dockerfile, as damaging conflicts could arise.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset