What is the difference between RUN and CMD in a Dockerfile?
CMD are both instructions used in Dockerfiles, but they have different purposes.
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, 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.
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.
The fastest log
search on the planet
Better Stack lets you see inside any stack, debug any issue, and resolve any incident.
How do I make a comment in a Dockerfile?
In a Dockerfile, you can add comments to provide information about the Dockerfile and the instructions in it. Comments in Dockerfiles start with the # symbol and continue to the end of the line. Fo...Questions
How to set image name in Dockerfile?
You can set the image name in a Dockerfile using the FROM instruction. The FROM instruction specifies the base image that your Docker image will be built upon. The basic syntax of the FROM instruct...Questions
How to update PATH environment variable in a Dockerfile?
To update the PATH environment variable in a Dockerfile, you can use the ENV instruction to set the new value of the PATH variable. Here's an example: FROM ubuntu Set a new value for the PATH envir...Questions
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
Make your mark
Join the writer's program
Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.Write for us
Build on top of Better Stack
Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our firstname.lastname@example.org
or submit a pull request and help us build better products for everyone.
See the full list of amazing projects on github