0
votes

I am trying to use the data directory from a preexisting database & bring up a new postgres docker container (same version 9.5) with its '/var/lib/postgresql/data' bind mounted to the data directory.

I find that even though i am able to bring up the container & use psql within the container to connect to it, external connections fail with invalid password. This despite me setting the POSTGRES_USER, POSTGRES_DB & POSTGRES_PASSWORD environment variables.

Is there a way to make this work? I also tried this method but ran into permission error,

"sh: 1: /usr/local/bin/init.sh: Permission denied"

Thanks

2

2 Answers

1
votes

This happends when your user/group id does not match the file owner. You should run your docker with --user

please have a look to Arbitrary --user Notes of https://hub.docker.com/_/postgres

Hope that will help you to fix your problem.

For composer look at https://docs.docker.com/compose/reference/run/

0
votes

OK i figured out the way to do this & it turns out to be very simple. All i did was,

  • Add a script & copy it into docker-entrypoint-initdb.d in my Dockerfile
  • In the script i had a loop that was waiting for the db to be up & running before resetting the superuser password & privileges.

Thanks