$@ blank in Bash script which is ENTRYPOINT unless --entrypoint

Viewed 534

Consider the following Dockerfile:

FROM ubuntu:xenial-20170802
RUN (echo '#!/bin/bash'; echo 'echo "args: $@"') > /run.sh && chmod a+x /run.sh
ENTRYPOINT /run.sh

Using Docker 1.12.6 (on an Ubuntu Zesty host, in case it matters), if I

docker build -t entrypoint-test .
docker run --rm entrypoint-test a b c

I just get

args: 

In other words, $@ is not working. However this seems to indicate that the shell script itself is OK:

docker run --rm --entrypoint /bin/bash entrypoint-test /run.sh a b c

producing

args: a b c

as expected. Even stranger,

docker run --rm --entrypoint /run.sh entrypoint-test a b c

works. Note that compared to the original command, I am doing nothing but overriding the ENTRYPOINT directive with an --entrypoint of the same value. So why would that make it work?

I cannot see anything in docs that would suggest argv would be blank in some cases, perhaps involving #! executable scripts.

Adding

cat /proc/$$/cmdline

to the shell script confirms that the arguments are not being passed along unless --entrypoint is used:

/bin/bash^@/run.sh^@a^@b^@c^@

vs.

/bin/bash^@/run.sh^@
1 Answers
Related