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
392 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 16, 2018 by Damon Salvatore
• 5,510 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
• 6,890 points
59 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,270 points
63 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 29, 2018 in DevOps & Agile by Tyrion anex
• 8,270 points
121 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer