What is the difference between CMD and ENTRYPOINT in a Dockerfile?

前端 未结 16 1944
自闭症患者
自闭症患者 2020-11-21 22:31

In Dockerfiles there are two commands that look similar to me: CMD and ENTRYPOINT. But I guess that there is a (subtle?) difference between them -

16条回答
  •  半阙折子戏
    2020-11-21 23:33

    I have read all answers and I want to summarize for better understanding at first glance like following:

    Firstly, the whole command that gets executed in the container includes two parts: the command and the arguments

    • ENTRYPOINT defines the executable invoked when the container is started (for command)

    • CMD specifies the arguments that get passed to the ENTRYPOINT (for arguments)

    In the Kubernetes In Action book points an important note about it. (chapter 7)

    Although you can use the CMD instruction to specify the command you want to execute when the image is run, the correct way is to do it through the ENTRYPOINT instruction and to only specify the CMD if you want to define the default arguments.

    You can also read this article for great explanation in a simple way

提交回复
热议问题