Today, I've just explored a feature when you start a postgres instance on Docker which allows you to set up initial data like CREATE ROLE or GRANT .
You may learn more details here
We create *.sql or *.sh script to run SQL statement or bash script to prepare initial data. Postgres container will run any *.sql and *.sh found in the directory (which containing docker-compose.yml) to do further initialization before starting the service.
NOTE: scripts in /docker-entrypoint-initdb.d are only run if you start the container with a data directory that is empty; any pre-existing database will be left untouched on container startup.
And visit my example code at my gist
Top comments (0)