I'm trying to understand a discrepancy between ENTRYPOINT
in Dockerfile and docker run --entrypoint
. The exec
form of ENTRYPOINT
allows multiple parameters,
# Source: https://docs.docker.com/engine/reference/builder/#entrypoint
ENTRYPOINT ["executable", "param1", "param2"]
but docker run --entrypoint=executable
accepts only one. Many examples show how to override ENTRYPOINT
with arguments, but they do so by also specifying CMD
:
docker run --entrypoint=executable image:latest param1 param2
Is there a technical limitation preventing a direct docker run --entrypoint
equivalent to ENTRYPOINT ["executable", "param1", "param2"]
? Docker Compose seems to support it with
# Source: https://docs.docker.com/compose/compose-file/compose-file-v3/#entrypoint
entrypoint: ["php", "-d", "memory_limit=-1", "vendor/bin/phpunit"]
as do other providers which work with Docker (e.g. AWS ECS). Or perhaps, internally, [...entrypoint_args, ...command_args]
is actually massaged into [entrypoint, ...command]
to make it compatible with docker run
?
The Docker cli uses the Golang CLI manager spf13/cobra to handle its flags such as --entrypoint
.
This is where the entrypoint is extracted:
flags.StringVar(&copts.entrypoint, "entrypoint", "", "Overwrite the default ENTRYPOINT of the image")
StringVar
from the spf13/pflag library will only extract the first string after the flag due to how it parses command line arguments. So it won't get all strings after the flag if they're separated by spaces or not enclosed in double quotes "
. So this seems to be that technical limitation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With