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

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

    CMD:

    • CMD ["executable","param1","param2"]: ["executable","param1","param2"] is the first process.
    • CMD command param1 param2: /bin/sh -c CMD command param1 param2 is the first process. CMD command param1 param2 is forked from the first process.
    • CMD ["param1","param2"]: This form is used to provide default arguments for ENTRYPOINT.

    ENTRYPOINT (The following list does not consider the case where CMD and ENTRYPOINT are used together):

    • ENTRYPOINT ["executable", "param1", "param2"]: ["executable", "param1", "param2"] is the first process.
    • ENTRYPOINT command param1 param2: /bin/sh -c command param1 param2 is the first process. command param1 param2 is forked from the first process.

    As creack said, CMD was developed first. Then ENTRYPOINT was developed for more customization. Since they are not designed together, there are some functionality overlaps between CMD and ENTRYPOINT, which often confuse people.

提交回复
热议问题