Understanding Dockerfile

Puneet Khanna
2 min readDec 12, 2021

Dockerfile is a file that lists the steps by which a docker image can be created locally, The image then is verified ( by yourself to see if it is desired ) and then is uploaded to the hub so that others can download that to spin containers.

Lets take the following example of the docker file which lists the steps or the content of the image. The image can have any util(s) to be preinstalled like a VM ovf which has the database service (mysql) already installed, the ports are configured so that the application service can talk to it and is ready to be used by anyone.Consider this as a bundle of different softwares to run and can be used to successfully create a working software to use or be used by different clients.

The following image is built “upon” nginx image which resides on hub.It updates itself and then installs curl , can install many other softwares as well if required. if you want to run a command start the line in the dockerfile with RUN, then use COPY . The entry point is the first command or work the docker “container that gets created with this image” will do , the CMD is the args passed in addition to this command, this can be passed from the command line or can be overriden by the YAML used to create the container( we will talk about pods and YAML later)

From nginx
RUN apt-get -y update
RUN apt-get install -y curl
ENTRYPOINT [“ls”]
CMD [“fileNameCanAlsoBepassedAsAnargument”]

Suppose you want to search for a file(to be passed by the user as argument while creating container) the DockerFile will look like

From nginx
RUN apt-get -y update
RUN apt-get install -y curl
ENTRYPOINT ["ls","-ltrh","|","grep"]
CMD ["filename"]
# ls -ltrh | grep "filename"

You do docker push to push this image to the repository , if you do just want to pull the image and not create a container yet , use docker pull .

How to build an image from the DockerFile ? The following command builds the image ( locally ) with tags puneet:latest1

docker build -t puneet:latest1 — < /home/user/Desktop/dockerFile

You can apply as many as tags to the file , considering these are different versions of the image as in the history

docker build -t image:1 — < /home/user/Desktop/dockerFile
docker build -t image:2 — < /home/user/Desktop/dockerFile
docker build -t image:3— < /home/user/Desktop/dockerFile

Thats it for now on the basics, Happy DockerFile building

--

--