DockerFile Commands Explained

DockerFile Commands Explained-cheat sheet-Tutorial


every dockerfile starts with from command. in the from command, we will mention base image for the docker image.


From node:latest



maintainer command is used to represent the author of the docker file.


the run command is used to run any shell commands. these commands will run on top of the base image layer. run commands executed during the build time. you can use this command any number of times in dockerfile.


the cmd command doesn’t execute during the build time it will execute after the creation of the container. there can be only one cmd command in dockerfile. if you add more than one cmd commands the last one will be executed and remaining all will be skipped. whatever you are mentioning commands with cmd command in dockefile can be overwritten with docker run command. if there is entrypint command in the dockerfile the cmd command will be executed after entry point command. with cmd command you can pass arguments to entrypoint command.

cmd command you can use in two types one is as executable for and another one is parameters form

parameters form:

CMD [“param1″,”param2”] this param1 and param2 will be passed to entrypoint command as a arguments.


in the above example, postgress is the first argument to entrypoint command

this is like running the shell script with one argument.  postgress

executable form:

CMD [“python”, “”]

python will be run in the container after the creation of the container.

overwrite the cmd commands with docker run:

after the creation of the image if you run the container with docker run <image> then cmd command “python” will be executed.

docker  run    <image>     /usr/bin/top

but if you run container  like docker run <image> /usr/bin/top then the cmd commands in docker file i,e python will not executed. this cmd command will be overwritten by /usr/bin/top command. only /usr/bin/top will run in the container after starting this conatiner.

so the cmd commands in dockerfile can be overwritten with docker run commands.


after creating the container, the container will listen on this port


this command is used to set environment variables in the container.



it will copy the files and directories from the host machine to the container. if the destination does not exist. it will create the directory.

COPY  .  /usr/src/app

here dot(.) means all files in host machine dockerfile directory, will be copied into container /usr/src/copy directory.



it will copy the files and directories from the host machine to the container and its support copy the files from remote URLs.


The first command that will execute in the container is entrypoint command. Entrypoint command will be executed before the cmd command.  If you mentioned more than one, only the last one will be executed and remaining all will be skipped. cmd command paraments are arguments to entrypoint command.

above commands will run as /  postgress

here postgress is the first argument to script


this command will set user id (uid) or username when running the image


It is just like Linux cd command. If you mention any path after workdir the shell will be changed into this directory. The next mentioned commands like run,cmd,entrypoint commands will be executed in this directory.

WORKDIR  /devops

RUN npm install

here npm install command will run on devops directory.




  • dockerfile commands tutorial
  • dockerfile commands explained
  • dockerfile commands cheat sheet
  • dockerfile commands list
  • dockerfile commands example
  • dockerfile commands pdf