What Is Dockerfile?

A Dockerfile is a text document that consists of commands with the help of which you create your own custom image. The docker build command is used to build an image from the Dockerfile, the -f flag with docker build to provide the path of your Dockerfile..

$ docker build -f /path/to/a/Dockerfile .   


Docker runs instructions mentioned in your Dockerfile in top to bottom order. The first instruction always must be FROM in order to set the Base Image.
You can also use RUN, CMD, FROM, EXPOSE, ENV, ENTRYPOINT etc instructions in your Dockerfile.

Here are examples of some commonly used instructions.


This instruction is used to set the Base Image for your custom image.


This instruction is used to execute any command for the current image.


This specifies command that is being executed while running docker. CMD is used in following form


This instruction is used to copy files or directories from source to the file system of the container at the destination.


  1. The source path must be inside the context of the build i.e. the build context.
  2. If source is a directory, then the entire contents of the directory are copied.


It is used to set the working directory for any RUN, CMD and COPY instruction that follows it in the Dockerfile. If the work directory does not exist, it will be created by default.

Here is an example of Dockerfile and its name should always start with Dockerfile.

FROM ubuntu    
RUN apt-get update -y
RUN apt-get install openjdk-8-jdk -y  
COPY abc.txt /abc.txt
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh 
ENTRYPOINT [“./entrypoint.sh”]  
Subscribe Now