How to pass argument to ENTRYPOINT with variable expansion?

  docker

I’m building a docker image based on some other image that is out of my control. The base image sets an ENTRYPOINT I want to use by simply passing arguments via the CMD command. I also need to use runtime variable expansion in the arguments. Here’s my Dockerfile

FROM base # I do not control base, but I need to call its ENTRYPOINT.

# The "as default parameters to ENTRYPOINT" form. Does not expand variables.
CMD [ "--port", "$PORT" ]

# The "exec" from. I can't use it, because I do not know path to the executable as the base image is outside my control.
CMD [ "executable", "--port", "$PORT" ]

# The "shell" form. Won't even build because "--port" is interpreted as flag of "CMD".
CMD --port $PORT

As explained in the code, none of the three forms offered by the docs works in my use case.

There are already similar question here on SO, but neither answers this particular use case. This one doesn’t comprise variable expansion. And this one doesn’t account for the inability to change the ENTRYPOINT.

Source: Docker Questions

LEAVE A COMMENT