1

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?

1 Answer 1

1

You're using the shell form of the ENTRYPOINT instruction. From the documentation:

The shell form:

ENTRYPOINT command param1 param2 

The shell form prevents any CMD or run command line arguments from being used.

Whilst in practice it's possible to hack your way around this by amending your instruction to:

ENTRYPOINT /entrypoint.sh "$0" "$@" 

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:

ENTRYPOINT ["/entrypoint.sh"] 

The only inconvenience you run into when using the exec form is the fact that it will not do variable substitution so something like:

ENTRYPOINT ["$HOME/entrypoint.sh"] 

Will not work as you would expect.


You might be tempted to do something like so:

ENTRYPOINT ["sh", "-c", "$HOME/entrypoint.sh"] 

However, 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

Sign up to request clarification or add additional context in comments.

4 Comments

The initial string-only format is exactly equivalent to your final ["sh", "-c", ...] option, and manually inserting the sh -c wrapper will bring back the same problems you're avoiding by changing to exec form.
Ah thanks for the heads up, I was actually just about to test this on my machine (I was documenting this on SO as I go, I will amend the answer now).
One minor thing, shell form should be ENTRYPOINT /entrypoint.sh "$0" "$@"
Just fixed, Thanks @Philippe .

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.