Overview of Dockerfile

This article is about the Docker image , many of us know that what is Docker , how it runs by pulling the docker images from docker hub. Here we will understand what is docker image , how it is created. So to know about the how the docker images are created , the answer is by Docker file. A Dockerfile is a list of instructions that define how to build and start your application. During the build phase, these instructions are executed. The Dockerfile allows image creation to be automated, repeatable and consistent.

To run an application inside of a container you first need to build the Docker Image. The Docker Image should contain everything required to start your application, including dependencies and configuration.

I will show you the simple sample Dockerfile and will understand about the each set of the instructions which are defined in the file to create the docker image.

Sample Dockerfile

#This is a sample Dockerfile to create Image 

FROM ubuntu 

MAINTAINER atul.yadav@gmail.com 

RUN apt-get update 

RUN apt-get install –y nginx 

EXPOSE 3000

CMD [“echo”,”Image created”] 

The first part of a Dockerfile is to define the base image. Docker has an embrace and extends approach. Your Dockerfile should only describe the steps required for your application. In our case the base image is Ubuntu , next is the maintainer who maintains the image. The next command is the RUN which has set of commands which will be executed in the base image which will first update the packages in the ubuntu base image and after the it will install nginx packages. Next is the EXPOSE which is allow the image to communicate on port 3000. The CMD instruction defines the default command to run when the Docker Container is started and it will display the message.

Now once your docker file is created then its time to build the image

Then run build command

docker build -t <nameofimage:tagname> <path of docker file>

Once your image is created then verify with the below command

docker images

You will able to see the newly created image with the tag and version.


Hope this article helps for the people who are interested in learning Dockers.

Thanks for reading.


To view or add a comment, sign in

More articles by Atul Y.

Others also viewed

Explore content categories