What is the difference between RUN and CMD in a Dockerfile?
RUN
and CMD
are both instructions used in Dockerfiles, but they have different purposes.
RUN
instruction
RUN
is used to execute commands during the build process of a Docker image. These commands are run in a new layer on top of the current image and their result is saved in the new image layer. The commands specified with RUN
are typically used to install software packages, update system configurations, create directories, and perform other tasks that are necessary to configure the image.
CMD
instruction
CMD
, on the other hand, is used to specify the default command to run when a Docker container is started from the image. This command is only executed when the container is started and it can be overridden by passing a different command to the docker run command line. CMD
is typically used to start a service or application in the container.
To summarize, RUN
is used to execute commands during the build process of a Docker image, while CMD
is used to specify the default command to run when a Docker container is started from the image.
-
What Is the Difference between CMD and ENTRYPOINT in a Dockerfile?
There is a big confusion around similarity and lack of clarity in the difference between the CMD and ENTRYPOINT instruction in Docker. Let’s clear things up. See the example Let’s say we want to cr...
Questions -
What Is the Difference between a Docker Image and a Container?
Docker image A Docker image ****is an immutable (unchangeable) file that contains the source code, libraries, dependencies, tools, and other files needed for an application to run. Sometimes these ...
Questions -
High Availabilty Architecture with Docker
Docker guides
Guides -
How to Copy Files from Docker Container to Host?
Before Docker 1.8, we could only copy files from the container to the host. However, as containers became even more popular, copying files to and from containers has become necessary. One of the re...
Questions
We are hiring.
Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.
Help us in making the internet more reliable.

Help us with developer education and get paid.

Reliability is the
ultimate feature
Delightful observability tools that turn your logs & monitoring into a secret weapon for shipping better software faster.
Explore Better Stack
