Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the differences between CMD and ENTRYPOINT in Dockerfile

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly shows you "what are the differences between CMD and ENTRYPOINT in Dockerfile". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn "what is the difference between CMD and ENTRYPOINT in Dockerfile".

When does # CMD and ENTRYPOINT work? Both CMD and ENTRYPOINT are the first instructions to be run after initializing image to container using the docker run instruction.

# format of CMD and ENTRYPOINT

ENTRYPOINT ["executable", "param1", "param2"] (exec form, preferred)

ENTRYPOINT command param1 param2 (shell form)

CMD ["executable", "param1", "param2"] (exec form, this is the preferred form)

CMD ["param1", "param2"] (as default parameters to ENTRYPOINT)

CMD command param1 param2 (shell form)

There are three CMD instruction formats on the official website, but I think there are only two (explained below):

CMD ["executable", "param1", "param2"] (exec form)

CMD command param1 param2 (shell form)

# when CMD is used with ENTRYPOINT

CMD (exec form) Dockerfile

FROM ubuntu:15.04CMD ["echo", "hello cmd"] ENTRYPOINT ["echo", "hello entry"]

Docker run result

Hello entry echo hello cmd

CMD (shell form) Dockerfile

FROM ubuntu:15.04CMD echo "hello cmd" ENTRYPOINT ["echo", "hello entry"]

Docker run result

Hello entry / bin/sh-c echo "hello cmd"

Docker will not judge whether the CMD is the first format or the second format according to the contents of CMD (exec form), but according to whether the ENTRYPOINT instruction exists in the Dockerfile file. I don't think the format should be distinguished according to the external conditions, so I think there are only two formats of the CMD instruction.

# how do CMD and ENTRYPOINT execute exec form instructions and use the exec command to run (see from the official website introduction)

The shell form instruction runs using the / bin/sh-c command (as can be seen from the results of the docker run above)

The difference between # CMD and ENTRYPOINT is to add parameter A to the docker run instruction. If there is only CMD instruction without ENTRYPOINT in Dockerfile, execute / bin/sh-c A. if there is ENTRYPOINT in Dockerfile, discard the contents of CMD instruction and pass A to ENTRYPOINT. A: it can be a parameter or multiple parameters

The above is all the content of the article "what is the difference between CMD and ENTRYPOINT in Dockerfile". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report