docker-library / postgres

Docker Official Image packaging for Postgres
http://www.postgresql.org
MIT License
2.16k stars 1.13k forks source link

docker-entrypoint.sh: executable shell script test is unreliable #1108

Closed mhw closed 8 months ago

mhw commented 1 year ago

docker-entrypoint.sh uses a .sh file's executable mode to decide whether to source or exec the shell script. Due to a long-standing issue on Docker Desktop for macOS when VirtioFS or gRPC FUSE are used all files mounted into the container from the host are executable according to test -x even if the executable bit is not set, so this test is unreliable. As a result non-executable scripts in /docker-entrypoint-initdb.d are executed, giving a Permission denied error and the script does not run.

Although this really needs fixing in Docker Desktop, it's potentially going to lead to hard-to-diagnose issues in Postgres initialisation so I thought it at least worth reporting here for visibility. A possible workaround for the Docker issue could be to use stat and grep: something like if stat -c '%A' "$f" | grep -q '^-..x'; then ....

yosifkit commented 1 year ago

We had a similar issue in https://github.com/docker-library/mysql/issues/862; no great conclusion there 😞. I'd rather not introduce hacky/fragile code when test -x is the correct detection. The filesystem presenting differing values is where the fix should happen.

To work around it, you can build an image FROM postgres:[version] that copies in your sh scripts.

mhw commented 1 year ago

Yeah, I'd not be keen on adding the workaround to replace test -x either.

I went with your suggestion in our code. For those who run into this issue the changes came down to the following:

tianon commented 8 months ago

I'd love to figure out where/why test -x is failing to return the correct answer, but I think that rabbit hole is out of scope here. :bow: :sweat_smile: :heart: