Docker – Building Files

We created our Docker File in the last chapter. It’s now time to building the Docker File. The Docker File can be built with the following command βˆ’

docker build 

Let’s learn more about this command.

docker build

This method allows the users to build their own Docker images.

Syntax

docker build  -t ImageName:TagName dir

Options

  • -t βˆ’ is to mention a tag to the image
  • ImageName βˆ’ This is the name you want to give to your image.
  • TagName βˆ’ This is the tag you want to give to your image.
  • Dir βˆ’ The directory where the Docker File is present.

Return Value

None

Example

sudo docker build –t myimage:0.1. 

Here, myimage is the name we are giving to the Image and 0.1 is the tag number we are giving to our image.

Since the Docker File is in the present working directory, we used “.” at the end of the command to signify the present working directory.

Output

From the output, you will first see that the Ubuntu Image will be downloaded from Docker Hub, because there is no image available locally on the machine.

output

Finally, when the build is complete, all the necessary commands would have run on the image.

commands

You will then see the successfully built message and the ID of the new Image. When you run the Docker images command, you would then be able to see your new image.

built meesages

You can now build containers from your new Image.

In this topic, we learnt about building the Docker File to know more click here.

This Post Has One Comment

Leave a Reply