What Is A Dockerfile: Everything You Need to Know

Docker tool is a vital part of the configuration management tool in most of the global companies. Docker tool runs an application with the help of dockerfile 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, Docker container and Dockerfile. However, Docker Image can be created only with the help of Dockerfiles. Moving forward, let us understand docker and dockerfile in detail.

Elevate Your Tech Career!

Docker Certified Associate Training CourseExplore Program
Elevate Your Tech Career!

What is Docker?

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.

Features of Docker:

  • Easy and faster configuration
  • Application isolation
  • Security management
  • High productivity
  • High scalability
  • Infrastructure independent

Docker container is a software package that has all the dependencies required to run an application.

Note: A Docker Image is a template of instructions used to create containers

What is a Dockerfile?

Before we discuss what is a Dockerfile, it is important to know what a Docker image is. 

Elevate Your Tech Career!

Docker Certified Associate Training CourseExplore Program
Elevate Your Tech Career!

Docker Image:

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:


# comments

command argument argument1...


# 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.

Earn 40% More Than Non-Certified Peers

Lean Six Sigma Expert Masters ProgramEnroll Now!
Earn 40% More Than Non-Certified Peers

List of Docker Commands for Creating a Dockerfile with example

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 - Creates a layer from the ubuntu:18.04
  • PULL - Adds files from your Docker repository
  • RUN - Builds your container
  • CMD - Specifies what command to run within the container

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. 

  • ENTRYPOINT allows specifying a command along with the parameters

Elevate Your Tech Career!

Docker Certified Associate Training CourseExplore Program
Elevate Your Tech Career!


ENTRYPOINT application "arg, arg1".


ENTRYPOINT echo "Hello, $name".

  • ADD command helps in copying data into a Docker image


ADD /[source]/[destination]


ADD /root_folder/test_folder

  • ENV provides default values for variables that can be accessed within the container


ENV key value


ENV value_1

  • MAINTAINER declares the author field of the images




MAINTAINER author_name

Earn 40% More Than Non-Certified Peers

Lean Six Sigma Expert Masters ProgramEnroll Now!
Earn 40% More Than Non-Certified Peers

How to Build a Docker Image and Docker Container Using Dockerfile?

First of all, you should create a directory in order to store all the Docker images you build.

  • Now, we will create a directory named ‘simplidocker’ with the command:

mkdir simplidocker

  • Move Docker image into that directory and create a new empty file (Dockerfile) in it:

cd simplidocker 

touch Dockerfile

  • Open the file with the editor. In this example, we opened the file using vi:

vi Dockerfile

  • Then, add the following content:

FROM ubuntu


RUN apt-get update

CMD ["echo", "Welcome to Simplilearn"]

  • 5.Save and exit the file.

Fuel Your 2024 Career Success in Cloud/DevOps

Free Webinar | 18th Dec, Monday | 7 PM ISTRegister Now!
Fuel Your 2024 Career Success in Cloud/DevOps

Build a Docker Image with Dockerfile

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.

Create a New Container

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. 

PRINCE2® Certification Exam Made Easy to Crack

PRINCE2® Foundation & Practitioner CertificationExplore Course
PRINCE2® Certification Exam Made Easy to Crack


With that, we have come to the end of the article, what is a dockerfile. In this write-up, we discussed what docker is, what is a 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!


When should I use Dockerfile?

One should use a Dockerfile when there’s a need to distribute/collaborate on the app’s operating system with a team. Use Dockerfile as the version control system for the entire app’s OS. Or use Dockerfile to run the code to the laptop in the same environment as the server you are working on. 

Is Dockerfile a text file?

Dockerfile is a text document containing all the commands the user requires to call on the command line to assemble an image. With the help of a Dockerfile, users can create an automated build that executes several command-line instructions in succession. 

How do I create a simple Dockerfile?

To create a Dockerfile, set up Docker and Docker Hub. Create the original Docker container and then create a file on it. Make changes to the container, and finally, create a new image. 

What is Dockerfile language?

Go language is used to write Docker. A Dockerfile is a text file that contains collections of instructions and commands that will be automatically executed in sequence in the docker environment for building a new docker image. 

What is Docker compose vs. Dockerfile?

The key difference between Docker compose, and Docker is that the Docker contents describe how to create and build a Docker image, while Docker compose is a command that runs Docker containers based on settings described in a docker-composed.yaml file. 

What is a .dockerignore file?

A .dockerignore file allows you to specify a list of files or directories that Docker is to ignore during the build process. It is similar to a .gitignore file, which is used when you build Git repositories. You can specify the list of files and directories inside the .dockerignore file. 

How do I commit a docker container?

First, you need to pull a docker image. Then deploy the container, modify it and commit the changes to the image. When you commit to changes, you essentially create a new image with an additional layer that modifies the base image layer. 

What is docker context?

With a docker context, importing and exporting context on different machines with the Docker installed gets easier. One can also use a docker context export command to export an existing context to a file, which can be imported to another machine with the docker client installed. 

What is the use of Docker in DevOps?

A Docker container image in DevOps is a lightweight, executable, and standalone package of software that includes everything needed to run an app, runtime, system tools, settings, system libraries, and code. Containers simplify the build/test/deploy pipelines in DevOps.  

Is Dockerfile COPY recursive?

COPY and ADD are the two commands that Docker provides for copying files from the host to the Docker image when building it. COPY command copies files recursively, given explicit source and destination directories or files. 

Is Dockerfile a Docker image?

A Docker image is built automatically by reading the instructions from a Dockerfile, a text file containing all commands needed to build a given image. A Dockerfile adheres to a specific set of instructions and format, producing a Docker image when you build it. 

About the Author

Sana AfreenSana Afreen

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.

View More
  • Disclaimer
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, and OPM3 are registered marks of the Project Management Institute, Inc.