Suppose that I have an entry-point to a shell script as I want to use some conditionals in a dockerfile. Is there a way to do something like this?
ENTRYPOINT ["./entry.sh", "lambda-name"]
Inside of entry.sh
#!/usr/bin/env bash
lambda_name=$1
echo "$lambda_name"
if [ "$lambda_name" = "a.handler" ]; then
CMD [ "a.handler" ]
elif [ "$lambda_name" = "b.handler" ];then
CMD [ "b.handler" ]
else
echo "not found"
fi
2
Answers
first of all you don’t need that complication.
why not like this?
also in your script you could use something like
at the end of your script. this would run all your arguments.
The
ENTRYPOINT
is the main container process. It executes when youdocker run
the built image; it’s too late to run any other Dockerfile directives at that point.In particular, the
ENTRYPOINT
gets passed the image’sCMD
(or a Composecommand:
or an alternate command after thedocker run image-name
) as arguments, and it can do whatever it wants with that. So at this point you don’t really need to "set the container’s command", you can just execute whatever command it is you might have wanted to run.With this setup, a fairly common Docker pattern is just to take whatever gets passed as arguments and to run that at the end of the entrypoint script.
That matches what you show in the question: if the first argument is
a.handler
then run that command, and so on.