Skip to content

Database initialization is trying to execute a script that is not an executable. It should source it. #1332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mljrg opened this issue Mar 17, 2025 · 4 comments

Comments

@mljrg
Copy link

mljrg commented Mar 17, 2025

I am using postgres:17 image, and in my docker-compose.yml file I have added:

    volumes:
      - pgdata:/var/lib/postgresql/data
      - ../init-db.sh:/docker-entrypoint-initdb.d/init-db.sh

The ../init-db.sh does not have the executable mode on the host:

-rw-r--r--@ 1 myuser staff 2218 14 Mar 14:02 init-db.sh

so it is expected to be sourced, but instead the container initialization is trying to execute it

/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init-db.sh
/usr/local/bin/docker-entrypoint.sh: line 174: /docker-entrypoint-initdb.d/init-db.sh: Permission denied

I have created a container to check what is going on

% docker run --rm -it -e POSTGRES_HOST_AUTH_METHOD=trust -v ./init-db.sh:/docker-entrypoint-initdb.d/init-db.sh postgres:17 bash 
root@f7ca7450b9d2:/# cd docker-entrypoint-initdb.d/
root@f7ca7450b9d2:/docker-entrypoint-initdb.d# ls -la
total 12
drwxr-xr-x 1 root root 4096 Mar 17 13:04 .
drwxr-xr-x 1 root root 4096 Mar 17 13:04 ..
-rw-r--r-- 1 root root 2218 Mar 14 14:02 init-db.sh
root@f7ca7450b9d2:/docker-entrypoint-initdb.d# [ -x init-db.sh ] && echo $?
0
root@f7ca7450b9d2:/docker-entrypoint-initdb.d#

so strangely the test [ -x init-db.sh ] is failing: it should have returned 1 !

Old issues related to this: #490 #452

The expected behavior is for the init-db.sh script to be sourced, not executed.

@tianon
Copy link
Member

tianon commented Mar 17, 2025

I'm guessing you're on macOS using Docker Desktop? IIRC, the file sharing implementation there has a quirk where test -x returns the wrong answer.

@tianon
Copy link
Member

tianon commented Mar 17, 2025

Aha, there it is; this is a duplicate of #1108

@mljrg
Copy link
Author

mljrg commented Mar 17, 2025

@tianon

I'm guessing you're on macOS using Docker Desktop?
Yes.

Sorry, that other issue was not caught in my search.

@mljrg
Copy link
Author

mljrg commented Mar 17, 2025

My solution (workaround) was to chmod +x init-db.sh, and move on ...

@mljrg mljrg closed this as completed Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants