Can Docker environment variables be used as an dynamic entrypoint runtime arg?

I’m trying to parameterize my Dockerfile running nodeJS so I can have my entrypoint command’s args be customizable on docker run so I can maintain one container artifact that can be deployed repeatedly with variations to some runtime args.

I’ve tried a few different ways, the most basic being

ENV CONFIG_FILE=default.config.js

ENTRYPOINT node ... --config ${CONFIG_FILE}

What I’m finding is that whatever value is defaulted remains in my docker run command even if I’m using -e to pass in new values. Such as

docker run -e CONFIG_FILE=desired.config.js

Another Dockerfile form I’ve tried is this:

ENTRYPOINT node ... --config ${CONFIG_FILE:-default.config.js}

Not specifying the environment variable with an ENV directive, but using bash expansion to specify a default value if nonexistent or null is found. This gives me the same behavior though.

Lastly, the last thing I tried was to create a bash script file that contains the same entrypoint command, then ADD it to the docker context and invoke it in my ENTRYPOINT. And this also seems to give the same behavior.

Is what I’m attempting even possible?

Source: StackOverflow