Difference between RUN and CMD in a docker file and when to use one or the other

0 votes

Which command to use to execute bash/shell commands i.e. ls -la.

When should I use CMD and where should I use RUN? 

What's the best practice about these two similar Dockerfile directives.

Can anyone help me with this?

Thanks.

Nov 16, 2018 in DevOps & Agile by Shubham
• 1,000 points
3,604 views

1 answer to this question.

0 votes

Here are the explanations for all the three commands i.e., RUN,CMD and ENTRYPOINT.

RUN :-  A Dockerfile can have many RUN steps that layer on top of one another to build the image.

CMD :- It is the command which the container executes by default when you launch the built image. A Dockerfile can only have one CMD. The CMD can be overridden when starting a container with docker run $image $other_command.

ENTRYPOINT :- It is very much similar to CMD and can modify the way a container starts an image.

I hope that the above explanation will resolve your doubts.

answered Nov 17, 2018 by Damon Salvatore
• 5,980 points

Related Questions In DevOps & Agile

+2 votes
1 answer

What is the difference between a container and an image in Docker?

 Below is reference which you can follow to know ...READ MORE

answered Sep 20, 2018 in DevOps & Agile by shubham
• 7,340 points
1,208 views
0 votes
1 answer

How can a script identify the difference between Docker Toolbox and Docker for Windows?

Now, the Toolbox works through docker-machine. The way ...READ MORE

answered Aug 24, 2018 in DevOps & Agile by Tyrion anex
• 8,700 points
824 views
+13 votes
2 answers
0 votes
1 answer

How to a run deployed app in Docker for Windows?

To deploy an ASP.NET web application to ...READ MORE

answered Aug 30, 2018 in DevOps & Agile by Tyrion anex
• 8,700 points
1,220 views
+1 vote
1 answer
+2 votes
1 answer
0 votes
2 answers

difference between the `COPY` and `ADD` commands in a Dockerfile

Hi, COPY and ADD are both Dockerfile instructions that serve similar purposes. They ...READ MORE

answered Dec 23, 2020 in DevOps & Agile by akhtar
• 38,260 points
4,968 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP