When I check the cmd
and entrypoint
of one docker image, I see something like this:
1 | cmd: zkServer.sh start-foreground |
It actually by default works as:
1 | /docker-entrypoint.sh zkServer.sh start-foreground |
Let’s see what is inside /docker-entrypoint.sh
:
1 | # Generate Zookeeper configuration |
It just like a wrapper and executes the passed parameters as a new command. This pattern gives me some inspirations. Actually lots of containers use this pattern, like Envoy, please search my blog <<Docker Entrypoint Script>>
About $@
, reference from https://stackoverflow.com/questions/9994295/what-does-mean-in-a-shell-script:
$@
is nearly the same as $*
, both meaning all command line arguments. They are often used to simply pass all arguments to another program (thus forming a wrapper around that other program).
The difference between the two syntaxes shows up when you have an argument with spaces in it:
1 | wrappedProgram "$@" |
For example:
1 | # in terminal, type: |
What you will get:
1 | # the same format as we passed |
"$@"
is by far the most useful for most situations because it preserves the integrity of each positional parameter.