How to pass an argument to Dockerfile entrypoint

Sadly the default ENTRYPOINT does not handle variables or arguments, so we to use a workaround and store it in an Environment Variable, which is consumed in a bash command.

ARG DLL_NAME    
ENV DLL_NAME=$DLL_NAME
ENTRYPOINT [ "/bin/bash", "-c", "exec dotnet ${DLL_NAME}" ]

An alternative way would be to create a symlink for the dll.

ARG DLL_NAME
RUN ln -s ./${DLL_NAME} main.dll
ENTRYPOINT ["dotnet", "main.dll"]

Example Docker build command with argument.

docker build -t counter-image -f Dockerfile --build-arg DLL_NAME=DotNet.Docker.dll .

Notes

  • exec: a shell built-in function that replaces the current program instead of forking a new process. [link]
  • PID 1: the binary specified in Dockerfile ENTRYPOINT will be the first process and receive process ID 1.
  • Why Your Dockerized Application Isn’t Receiving Signals [link]
  • Docker Arg and Entrypoint [github]