postgres: postgres /docker-entrypoint.sh not running scripts in /docker-entrypoint-initdb.d/

I’m having trouble writing a script to /docker-entrypoint-initdb.d/ and having Docker run it from /docker-entrypoint.sh.

  • It looks like /docker-entrypoint.sh is supposed to source any scripts it finds in /docker-entrypoint-initdb.d/. I verified I’m running this version of the script by cating the script and verifying this is the expected behavior.
  • I followed the instructions in “justfalter”'s comment here: https://registry.hub.docker.com/_/postgres/ to add a fix-acl.sh file and put it in the correct folder. I double checked the folder name was correct.
  • I also mirrored the commands in the /docker-entrypoint.sh script to check that the script could be sourced and would produce the desired behavior.
  • When I do “docker run”, it’s clear that Postgres starts but the specified line was not added to pg_hba.conf. I double checked this by verifying the mtime of pg_hba.conf - it wasn’t touched or overwritten after my script ran. I also tried having my script touch various files to just verify that it ran, with no success.

I’m at a loss for how to continue debugging this; I placed a file in the place that it’s supposed to go, verified that the script runner that starts postgres should run it, and verified that the script does what I want, and I don’t see any output (a changed pg_hba.conf, or even a simple file).

I’m running the newest version of everything; starting Docker inside of a Ubuntu Virtualbox being provisioned from Vagrant. I share one folder from the Docker container to the host VM - the data folder containing pg_hba.conf.

Would appreciate your help! Kevin

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 21 (8 by maintainers)

Most upvoted comments

I just ran into this problem. I feel the initdb scripts will only run when the volume is first created should be made clear in the image description here.

I hit this problem - the issue is that the script is only run if there is no postgres data directory 😉

if [ -z "$(ls -A "$PGDATA")" ]; then

I think it would be better to have the script run a “initdb” function for all brand spanking new installations, and a “always run” function

hth

@danwyry, my newest idea is that the volume was persisting. With docker compose it tries really hard to keep volumes (ie your initialized database files). Most of the entrypoint script only runs on first initialization. docker-compose rm -v should get rid of all the containers and their volumes if you want to start fresh on the database.

Any ETA on when we would be able to easily re-launch the init script (via a command maybe?), without removing the volumes?