A Dockerfile is a text document that contains commands that are used to assemble an image. We can use any command that call on the command line. Docker builds images automatically by reading the instructions from the Dockerfile.
If we use the Docker images command, we can see the existing images in our system. But Docker also gives you the capability to create your own Docker images, and it can be done with the help of Docker Files
A Docker File is a simple text file with instructions on how to build your images.
The docker build command is used to build an image from the Dockerfile. You can use the -f flag with docker build to point to a Dockerfile anywhere in your file system.
Note: It is text file and saved without any extension. We can also say that it is text file, which is composed of various commands and arguments listed to automatically perform action on base image in order to get the new one.
Dockerfile Instructions
#This is a sample Image
FROM ubuntu (It is used to define the base Image)
MAINTAINER demousr@gmail.com
RUN apt-get update
RUN apt-get install –y nginx
CMD [“echo”,”Image created”]
Explanation:
The first line "#This is a sample Image" is a comment. You can add comments to the Docker File with the help of the # command
The next line has to start with the FROM keyword. It tells docker, from which base image you want to base your image from. In our example, we are creating an image from the ubuntu image.
The next command is the person who is going to maintain this image. Here you specify the MAINTAINER keyword and just mention the email ID.
The RUN command is used to run instructions against the image. In our case, we first update our Ubuntu system and then install the nginx server on our ubuntu image.
The last command is used to display a message to the user.
Step 3
Save the file. In the next chapter, we will discuss how to build the image.
Interview question:
Docker Hub is a registry service on the cloud that allows you to download Docker images that are built by other communities. You can also upload your own Docker built images to Docker hub
RUN
steps that layer on top of one another to build the image.
No comments:
Post a Comment
Thank you for visiting my blog