15

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?

1
  • 2
    (This is a good reason to prefer CMD to ENTRYPOINT for routine use, IMHO.) Commented Feb 12, 2021 at 12:33

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Ah I see, thank you. Sounds like this technical limitation is limited to the docker CLI, and does not affect other alternatives (e.g. the Docker Engine API).
@mxxk Yes, exactly. The CLI just populates the same struct and the underlying type that sets the config is a string slice but the CLI always passes it a string: github.com/moby/moby/blob/v1.13.1/api/types/container/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.