1

I have seen some images that based on the inspect have both CMD and ENTRYPOINT set.
What is the idea of this? What use cases are served when both are set?

Jim
  • 3,845
  • 3
  • 22
  • 47

1 Answers1

3

per https://docs.docker.com/engine/reference/builder/#cmd

CMD ["param1","param2"] (as default parameters to ENTRYPOINT)

this means that CMD can be used as a list of parametres to the entrypoint.

UPD 1

the idea here is that you can specify the entrypoint (binary to run at start) and then have CMD parameters to this entrypoint which can be overridden.

UPD 2

Here is an example:

cat Dockerfile
FROM busybox
ENTRYPOINT ["ls"]
CMD ["etc"]

now that if you build the image and run it without any arguments, it will product the list with the content of etc folder

$ docker run lister
group
hostname
hosts
localtime
mtab
network
passwd
resolv.conf
shadow

if you do specify the arguments though, you can override the CMD and list the content of a different folder

$ docker run lister var
spool
www

so the executable stays the same in both cases, while the CMD in the Dockerfile is defining the default argument to this binary. Then we can override when we run the container.

jabbson
  • 4,390
  • 1
  • 13
  • 23