How to Create User/Database in Script for Docker Postgres
I Have Been Trying to Set up a Container for a Development Postgres Instance by Creating a Custom User & Database. I Am Using the Official Postgres Docker...
I have been trying to set up a container for a development postgres instance by creating a custom user & database. I am using the official postgres docker image. In the documentation it instructs you to insert a bash script inside of the /docker-entrypoint-initdb.d/ folder to set up the database with any custom parameters.
My bash script: make_db.sh
su postgres -c "createuser -w -d -r -s docker"
su postgres -c "createdb -O docker docker"
Must Read
Dockerfile
FROM library/postgres
RUN ["mkdir", "/docker-entrypoint-initdb.d"]
ADD make_db.sh /docker-entrypoint-initdb.d/
The error I get from the docker logs -f db (db is my container name) is:
createuser: could not connect to database postgres: could not connect to server: No such file or directory
It seems that the commands inside of the /docker-entrypoint-initdb.d/ folder are being executed before postgres is started. My question is, how do I set up a user/database programmatically using the official postgres container? Is there any way to do this with a script?