I'm late to this thread, and I appreciate that there's already an accepted answer, but why not copy the script into the image's path, which I believe is /usr/local/bin. Then, you shouldn't need to mess around with setting execute permissions. I started doing this after looking at the Postgres 17 Bookworm Dockerfile.