Lesson 3 of 12By Sana Afreen
Last updated on Mar 5, 20212530Docker tools are a vital part of the management of most global companies. Docker tool runs an application with a high level of abstraction and security. Hence, many companies are extensively adopting the tool to achieve high network availability, service continuity, and service provision with high scalability.
However, global news wire has confirmed that the demand for docker tools in the market will eventually grow from USD 217 million to USD 993 million by 2024. This growth is exponential.
The reason for Docker being so popular is Docker image, and Docker Image can be created only with the help of Dockerfiles. Moving forward, let us understand dockerfile in detail.
In this article, you will be exploring the following topics:
Docker is a configuration management tool that is used to automate the deployment of software in lightweight containers. These containers help applications to work efficiently in different environments.
Docker container is a software package that has all the dependencies required to run an application.
Features of Docker:
Note: A Docker Image is a template of instructions used to create containers
Before we discuss what Dockerfile is, it is important to know what a Docker image is.
A Docker Image is a read-only file with a bunch of instructions. When these instructions are executed, it creates a Docker container.
Dockerfile is a simple text file that consists of instructions to build Docker images.
Mentioned below is the syntax of a Dockerfile:
Syntax
# comments
command argument argument1...
Example
# Print "Get Certified. Get Ahead"
Run echo "Get Certified. Get Ahead"
Now, let's have a look at how to build a Docker image using a dockerfile.
Before we create our first Dockerfile, it is important to understand what makes up the file.
Dockerfile consists of specific commands that guide you on how to build a specific Docker image.
The specific commands you can use in a dockerfile are:
FROM, PULL, RUN, and CMD
Mentioned below is an example of the dockerfile with the important commands
FROM ubuntu:18.04
PULL. /file
RUN make /file
CMD python /file/file.py
Have a look at the diagrammatic representation of how a dockerfile looks in a docker image:
Moving forward, let’s go through some of the most common Docker commands used while creating dockerfiles. Along with the syntax, we are explaining the commands with examples, so you can start experimenting with them right away.
Syntax
ENTRYPOINT application "arg, arg1".
Example
ENTRYPOINT echo "Hello, $name".
Syntax
ADD /[source]/[destination]
Example
ADD /root_folder/test_folder
Syntax
ENV key value
Example
ENV value_1
Syntax
MAINTAINER [name]
Example
MAINTAINER author_name
First of all, you should create a directory in order to store all the Docker images you build.
mkdir simplidocker
cd simplidocker
touch Dockerfile
vi Dockerfile
FROM ubuntu
MAINTAINER simpli
RUN apt-get update
CMD ["echo", "Welcome to Simplilearn"]
Let’s first declare the path where we will be storing the dockerfile simplidocker
docker build [OPTIONS] PATH | URL | -
Now, let’s build a basic image using a Dockerfile:
docker build [location of your dockerfile]
Now, by adding -t flag, the new image can be tagged with a name:
docker build -t simpli_image
Once the Docker image is created, you can verify by executing the command:
docker images
The output should show simpli_docker available in the repository.
Now, create a Docker container from the Docker image we created in the previous step.
Let’s name the container “simplilearn” and create it with the command:
docker run --name simplilearn simpli_docker
The message ‘Welcome to Simplilearn’ should appear in the command line, as seen in the image above.
Congratulations, you just created a Docker image and a Docker container using a Dockerfile.
Enroll for the Docker Certified Associate Training Course to learn the core Docker technologies like the Docker Containers, Docker Compose, and more.
With that, we have come to the end of the article, what is dockerfile. In this write-up, we discussed what docker is, what is dockerfile, syntax of dockerfile, important commands to create a docker image using a dockerfile, and how to build a docker image using a dockerfile.
If you are keen on furthering your knowledge with an in-depth understanding of the Docker tool, Simplilearn can be an ideal destination for you. This Docker In-Depth Training Course helps interested individuals learn both the basic and advanced concepts of Docker. By completing this certification program, you will gain hands-on experience on creating flexible application environments with Docker.
Do you have any doubts about this topic? Please feel free to place your questions in the comments section of this ‘What Is Dockerfile’ article. Our subject matter experts will get back to you at the earliest, on the same!
Sana Afreen is a Senior Research Analyst at Simplilearn and works on several latest technologies. She holds a degree in B. Tech Computer Science. She has also achieved certification in Advanced SEO. Sana likes to explore new places for their cultures, traditions, and cuisines.