0

I'm trying to figure out the ordering and priority of Dockerfile entrypoint, cmd and run. And additionally how each persists over stopping and restarting the container.

Supposing:

A docker container is configured to have an entrypoint program_1. It is then started with docker run my_container program_2.

The container is then stopped and restarted with docker stop my_container docker start my_container.

Which and in what order will the commands be run?

I'm specifically interested in the whether the command from docker run will persist.

Cjen1
  • 1,826
  • 3
  • 17
  • 47
  • 4
    Possible duplicate of [What is the difference between CMD and ENTRYPOINT in a Dockerfile?](https://stackoverflow.com/questions/21553353/what-is-the-difference-between-cmd-and-entrypoint-in-a-dockerfile) – RQDQ Sep 20 '18 at 15:52
  • Also, if you stop a container and then start it again it uses the same ENTRYPOINT and CMD. There are ways to change the command, but not for the faint of heart. For example, see: https://stackoverflow.com/a/32353134/5753290. – Andrew Sep 20 '18 at 15:59
  • @Andrew I'm specifically wondering regarding the run command, whether it will persist over restarts – Cjen1 Sep 20 '18 at 16:04
  • Yes, it is persisted. For example: $ docker run --name run-test -dt debian /bin/sh -c "while [ true ]; do date; sleep 5; done" b5823b0e1d135e5535e1845f96916c870294595a1f0ed70ca59dcda99572cb0e $ docker logs run-test Thu Sep 20 20:48:51 UTC 2018 $ docker stop run-test run-test $ sleep 60 && docker start run-test && docker logs -f run-test run-test Thu Sep 20 20:48:51 UTC 2018 Thu Sep 20 20:48:56 UTC 2018 Putting code in the comment did not work as I expected, but please let me know if you'd like me to put it in an answer. – Andrew Sep 20 '18 at 20:56

0 Answers0