Building an image using a Dockerfile
The Dockerfile is a text-based build instruction file that enables us to define the content of the Docker image and automate image creation. The Docker build engine reads the instruction in the Dockerfile
line by line and constructs the image as prescribed. In other words, Dockerfile
helps us to craft an image repeatedly in an automated fashion. The images created using Dockerfiles
are considered immutable.
Getting ready
Before we begin, we need a Dockerfile with build instructions. To make one, we need to go through the following steps:
- Create an empty directory:
$ mkdir sample_image$ cd sample_image
- Create a file named
Dockerfile
with the following content:
$ cat Dockerfile# Use ubuntu as the base image FROM ubuntu # Add author's name LABEL maintainer="Jeeva S. Chelladhurai" # Add the command to run at the start of container CMD date
How to do it...
Perform the following steps:
- Run the following command inside the directory where we created the
Dockerfile
...