CMD
The main purpose of a CMD is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well.
The CMD instruction has three forms:
CMD ["executable","param1","param2"] (exec form, this is the preferred form)
CMD ["param1","param2"] (as default parameters to ENTRYPOINT)
CMD command param1 param2 (shell form)
ENTRYPOINT
An ENTRYPOINT allows you to configure a container that will run as an executable.
ENTRYPOINT has two forms:
ENTRYPOINT ["executable", "param1", "param2"] (exec form, preferred)
ENTRYPOINT command param1 param2 (shell form)
简单来说,ENTRYPOINT 是正统地用于定义容器启动以后的执行体的,是容器的 “入口”,CMD 用来定义容器的默认的可执行体,即 docker run 不加执行命令时默认使用 CMD 里定义的可执行体。另外,CMD 还可以用来为 ENTRYPOINT 提供默认参数。
一般还是会用entrypoint的中括号形式作为docker 容器启动以后的默认执行命令,里面放的是不变的部分,可变部分比如命令参数可以使用cmd的形式提供默认版本,也就是run里面没有任何参数时使用的默认参数。如果我们想用默认参数,就直接run,否则想用其他参数,就run 里面加参数
|