0

Assume I have a base image with entrypoint/cmd, and a new layer built upon it also has an entrypoint/cmd.

For example:

Base:

    entrypoint ["base-start.sh"]
    cmd ["-initialize"]

Assume they will output a timestamp and a message like

    2018-08-31 15:00:00 base image initializing(2 min remaining).
    2018-08-31 15:02:00 base image initialized.

New layer:

    cmd /layer-start.sh

Assume output:

    2018-08-31 15:00:00 layer cmd executed.

Now I'd like to know would they both be executed and if they do, what is the execution order?

Which one is the result?

  1. Base cmd and layer cmd start in parallel.

    2018-08-31 15:00:00 base image initializing(2 min remaining).
    2018-08-31 15:00:00 layer cmd executed.
    2018-08-31 15:02:00 base image initialized.
    
  2. Layer cmd start after base cmd exits.

    2018-08-31 15:00:00 base image initializing(2 min remaining).
    2018-08-31 15:02:00 base image initialized.
    2018-08-31 15:02:01 layer cmd executed.
    
  3. Base image cmd is overriden.

    2018-08-31 15:00:00 layer cmd executed.
    

And if base image use cmd directly instead of entrypoint + cmd, would the senario be different?

Thank you in advance.

Ziyan Li
  • 43
  • 4

1 Answers1

4

As per the docs:

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.

And for ENTRYPOINT:

Only the last ENTRYPOINT instruction in the Dockerfile will have an effect.

And if you have a combination of CMD and ENTRYPOINT see the table from the docs for reference:

enter image description here

Additionally, this has also been answered here

moebius
  • 2,061
  • 11
  • 20