According to the usage guide for the official PostreSQL Docker image, all you need is:
Dockerfile
FROM postgres
ENV POSTGRES_DB my_database
COPY psql_dump.sql /docker-entrypoint-initdb.d/
The POSTGRES_DB
environment variable will instruct the container to create a my_database
schema on first run.
And any .sql
file found in the /docker-entrypoint-initdb.d/
of the container will be executed.
If you want to execute .sh
scripts, you can also provide them in the /docker-entrypoint-initdb.d/
directory.