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

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

    Most people explain it perfectly here, so I won't repeat all the answers. But to get a good feeling I would suggest testing it yourself by looking at the processes in the container.

    Create a tiny Dockerfile of the form:

    FROM ubuntu:latest
    CMD /bin/bash
    

    Build it, run it in with docker run -it theimage and run ps -eo ppid,pid,args in the container. Compare this output to the output you receive from ps when using:

    • docker run -it theimage bash
    • Rebuilding the image but with ENTRYPOINT /bin/bash and running it in both ways
    • Using CMD ["/bin/bash"]
    • ...

    This way you will easily see the differences between all possible methods for yourself.

提交回复
热议问题