CMD vs ENTRYPOINT in a Dockerfile

常常忘記,很粗略的筆記一下
經同事說明

根據:

CMD

  • The CMD specifies arguments that will be fed to the ENTRYPOINT.
  • There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.

ENTRYPOINT

  • The ENTRYPOINT specifies a command that will always be executed when the container starts.
  • An ENTRYPOINT allows you to configure a container that will run as an executable.

應該是這樣子:

  • 一個 Dockerfile 內只能有一個 CMD,如果有多,生效會是最後一個 CMD
  • CMD 會被當成 ENTRYPOINT 參數
  • ENTRYPOINT 預設是 /bin/sh -c
  • CMD 沒有預設值

初步的感覺有點像
今天 Dockerfile 只有

1
FROM ubuntu
1
2
⚡ docker build -t ajdfajdfl/test-entrypoint .
⚡ docker run --rm --name test ajdfajdfl/test-entrypoint ls

也就是
預設會是這樣 ENTRYPOINT + CMD/bin/sh -c "ls"