openresty / docker-openresty

Docker tooling for OpenResty
https://hub.docker.com/r/openresty/openresty
BSD 2-Clause "Simplified" License
947 stars 533 forks source link

Use ENTRYPOINT + CMD for easier configurability #146

Open ambis opened 4 years ago

ambis commented 4 years ago

Now there is CMD ["/usr/local/openresty/bin/openresty", "-g", "daemon off;"], but it could be

ENTRYPOINT ["/usr/local/openresty/bin/openresty"]
CMD ["-g", "daemon off;"]

And if I want to override the -g argument, I could do just

docker run openresty/openresty:alpine -g "daemon off; env MY_ENV_FOR_LUA;"

Without having to be concerned where the openresty binary resides.

How to verify functionality

Dockerfile

FROM openresty/openresty:alpine

ENTRYPOINT ["/usr/local/openresty/bin/openresty"]
CMD ["-g", "daemon off;"]

Build it

docker build -t test .

Run it

docker run --rm -it -e FOO=bar test -g 'daemon off; env FOO;'

Exec into and see process with top

    {openresty} nginx: master process /usr/local/openresty/bin/openresty -g daemon off; env FOO;
neomantra commented 4 years ago

Thanks for your suggestion and your demonstration. We used to use ENTRYPOINT, but then a user suggested using CMD. See #51 and #52.

It seems like it could go both ways. I eventually sided with CMD, mostly because that is how the Nginx images work.

I note that your suggestion (versus the old implementation) combines CMD and ENTRYPOINT. This is usually done when the image is intended to always use the same ENTRYPOINT. But, some users invoke other binaries from this image, e.g. resty and luajit.