Whilst developing my Dockerfile, I ran into an issue with the Entrypoint instruction script; it's not taking my docker run arguments in.
Here is an example of what I tried, given:
COPY ./entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT /entrypoint.sh
With the following entrypoint.sh:
#!/bin/bash
echo "I received:" "$@"
When I run the command:
docker run given/image:latest "A B C"
I expected the output:
I received: A B C
But instead, it was:
I received:
Am I missing something obvious here?
You're using the shell form of the ENTRYPOINT instruction. From the documentation:
Whilst in practise it's possible to hack your way around this by amending your instruction to:
However, I would recommend using the exec form as it passes Unix signals. (i.e.
SIGTERM;docker stop <container)Which is a simple syntax change:
The only inconvenience you run into when using the exec form is the fact that it will not do variable substitution so something like:
Might not work as you would expect. Instead, you could do something like:
(Do note that you will still run into the same Unix signals problem if you wrapped your command with
sh -c. Thanks @David Maze)For further details, see: Dockerfile reference - exec form ENTRYPOINT example