Building a Docker image

To build a Docker image from our previously created Dockerfile that contains the following instructions:

FROM httpd:latest
COPY index.html /usr/local/apache2/htdocs/

We'll go to a Terminal to head into the directory that contains the Dockerfile, and then execute the docker build command with the following syntax:

docker build -t demobook:v1 .

The -t argument indicates the name of the image and its tag. Here, in our example, we call our image demobook and add the v1 tag.

The . (dot) at the end of the command specifies that we will use the files in the current directory. The following screenshot shows the execution of this command:

Executing the docker build command downloads the base image indicated in the Dockerfile from Docker Hub, and then Docker executes the various instructions that are mentioned in the Dockerfile.

Note that if during the first execution of the docker build command, you get the Get https://registry-1.docker.io/v2/library/httpd/manifests/latest: unauthorized: incorrect username or password error, then execute the docker logout command, then restart the docker build command, as indicated in this article: https://medium.com/@blacksourcez/fix-docker-error-unauthorized-incorrect-username-or-password-in-docker-f80c45951b6b.

At the end of the execution, we obtain a locally stored Docker demobook image.

The Docker image is stored in a local folder system depending on your OS. For more information about the location of Docker images, read this article: http://www.scmgalaxy.com/tutorials/location-of-dockers-images-in-all-operating-systems/.

We can also check that the image is successfully created by executing the following Docker command:

docker images

Here's its output:

This command displays the list of Docker images on my local machine, and we see the demobook image we just created as well as the basic httpd image that was downloaded from DockerHub. So, the next time the image is built, the httpd image will not need to be downloaded again.

Now that we have created the Docker image of our application, we will instantiate a new container of this image.

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

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