Reputation: 1804
Is there a way to add a --help message to a docker image that can be displayed when running from the command line? I haven't been able to find anything online or in the docker docs.
Upvotes: 0
Views: 90
Reputation: 60074
You can add this in the entrypoint as mentioned by @Yazou, I am adding entrypoint in Dockerfile, you can create separate file as well.
This will log
help message if container started with --help
CMD otherwise it will start the desired process.
FROM alpine
RUN echo $'#!/bin/sh \n\
echo "to see image helo run docker with --help" \n\
if [ "${1}" == "--help" ]; then \n\
echo "docker run -it --rm my_app argument1 argument1" \n\
echo "my_app --option etc" \n\
else \n\
exec "$@" \n\
fi \n\
' >> /bin/entrypoint.sh
RUN chmod +x /bin/entrypoint.sh
entrypoint ["entrypoint.sh"]
To test --help
flag
docker run -it my_image --help
output
to see image helo run docker with --help
docker run -it --rm my_app argument1 argument1
my_app --option etc
without --help
flag
docker run -it my_image
output
to see image helo run docker with --help
Upvotes: 1