MariaDB / mariadb-docker

Docker Official Image packaging for MariaDB
https://mariadb.org
GNU General Public License v2.0
770 stars 438 forks source link

Container won't keep running if started from own entrypoint using `source` command #275

Closed javolek closed 4 years ago

javolek commented 4 years ago

Finally I decided to make this an issue as I spent a few hours figuring out why my container that builds on top of mariadb's image won't start, maybe to help others having the same issue. The problem occurred after 3b2e52a6a0a525d879053a33886f35d3a5c38603.

It seams that running mariadb using just source command with mariadb's entrypoint is now deprecated. Doing so silently exits the running container. This broke all our images build on top of mariadb image as we used to start the mariadb from our image running the mariadb's entrypoint like this:

source /usr/local/bin/docker-entrypoint.sh $@

The cause are the following lines in the mariadb's entrypoint: https://github.com/docker-library/mariadb/blob/ad6b97a27e6c09b81fb8d1e091b276b8ca5fff76/10.1/docker-entrypoint.sh#L328-L331

Workaround to emulate the old behavior:

source /usr/local/bin/docker-entrypoint.sh
_main $@

Suggestion for a fix: When calling the mariadb's entrypoint using source command with one or more parameters, either report error or emulate the previous behavior. It may be also useful, when sourcing mariadb's entrypoint to inform user about that situation. Now it looks like there is something wrong because nothing happens when doing so.

tianon commented 4 years ago

To be honest, I'm not sure what benefit you get from doing source /usr/local/bin/docker-entrypoint.sh $@ instead of just running the script? Can you please elaborate on what you're trying to accomplish with that? (I don't think it's a usage we've ever officially recommended nor supported, and I'm trying to understand the intent because I'm not seeing a benefit to using source there. :confused:)

javolek commented 4 years ago

There may be no benefit at all. I just felt no urge to start a new shell by "just running" a script and it was also working fine before. source is a legitimate way of running scripts, isn't it? Also I didn't find any documentation showing how to use the existing entrypoint of maria-db's image at all.

yosifkit commented 4 years ago

There is no documentation as of yet for the new script. The new interface supports sourcing but not to run it, if you want to run the entrypoint, do that directly. While sourcing does run and execute any lines in the script, it is often used for importing all the functions of the file so that you can use them in a custom way.

The _main function is the current example of how the functions are used and the underscore at the beginning is to denote functions that are private for the entrypoint (and may change at any time) while the non-underscored are public interfaces that users can string together to create their own startup (like this example in postgres).

I don't see a reason for sourcing vs just exec so while you can just call _main, it may change names or functionality in later releases. Your most stable fix is to just run the script instead of sourcing it:

exec docker-entrypoint.sh "$@"
javolek commented 4 years ago

Thanks @yosifkit, that is exactly the statement I was missing:

Your most stable fix is to just run the script instead of sourcing it:

exec docker-entrypoint.sh "$@"