Skip to content

Instantly share code, notes, and snippets.

@kirilkirkov
Created November 14, 2022 18:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirilkirkov/a4125a5609cb19ce0e30da6e55052f43 to your computer and use it in GitHub Desktop.
Save kirilkirkov/a4125a5609cb19ce0e30da6e55052f43 to your computer and use it in GitHub Desktop.
Whats the difference between cmd and run in Dockerfile

RUN - command triggers while we build the docker image.

CMD - command triggers while we launch the created docker image.


RUN EXPLAIN: RUN is an image build step, the state of the container after a RUN command will be committed to the container image. A Dockerfile can have many RUN steps that layer on top of one another to build the image. RUN: Commands May not Execute if Images are Cached. RUN instruction allows you to install your application and packages required for it. It executes any commands on top of the current image and creates a new layer by committing the results. Often you will find multiple RUN instructions in a Dockerfile.

CMD EXPLAIN: If a docker file has more than 1 CMD commands then all of them are ignored except the last one. As this command will not execute anything but just set the default command. Its mostly used to execute your start point. Eg. CMD ["npm", "start"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment