Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker run --entrypoint with multiple parameters

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?

like image 483
mxxk Avatar asked Feb 12 '21 04:02

mxxk


Video Answer


1 Answers

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.

like image 153
tentative Avatar answered Sep 28 '22 05:09

tentative