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

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

    The official documentation of Dockerfile best practices does a great job explaining the differences. Dockerfile best practices

    CMD:

    The CMD instruction should be used to run the software contained by your image, along with any arguments. CMD should almost always be used in the form of CMD ["executable", "param1", "param2"…]. Thus, if the image is for a service, such as Apache and Rails, you would run something like CMD ["apache2","-DFOREGROUND"]. Indeed, this form of the instruction is recommended for any service-based image.

    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).

提交回复
热议问题