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

前端 未结 16 1757
自闭症患者
自闭症患者 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:18

    • A Dockerfile should specify at least one CMD or ENTRYPOINT instruction

    • Only the last CMD and ENTRYPOINT in a Dockerfile will be used

    • ENTRYPOINT should be defined when using the container as an executable

    • You should use the CMD instruction as a way of defining default arguments for the command defined as ENTRYPOINT or for executing an ad-hoc command in a container

    • CMD will be overridden when running the container with alternative arguments

    • ENTRYPOINT sets the concrete default application that is used every time a container is created using the image

    • If you couple ENTRYPOINT with CMD, you can remove an executable from CMD and just leave its arguments which will be passed to ENTRYPOINT

    • The best use for ENTRYPOINT is to set the image's main command, allowing that image to be run as though it was that command (and then use CMD as the default flags)

提交回复
热议问题