I have the following docker-compose part
postgres:
container_name: postgres
image: postgres
environment:
POSTGRES_PASSWORD: "postgres"
ports:
- "15432:5432"
volumes:
- /root/database:/var/lib/postgresql/data
networks:
- production-network
restart: unless-stopped
depends_on:
- rest-proxy
- broker
What should I do to run a .sql file and restore the db as soon as I run docker-compose ?
Based on the docker image documentation you can include initialization scripts if you mount under /docker-entrypoint-initdb.d
. It should work with both *.sql
, *.sql.gz
, or *.sh
. So in your example, the compose file should look something like this:
postgres:
container_name: postgres
image: postgres
environment:
POSTGRES_PASSWORD: "postgres"
ports:
- "15432:5432"
volumes:
- /root/database:/var/lib/postgresql/data
- /root/database-init/init-user-db.sql:/docker-entrypoint-initdb.d/init-user-db.sql:ro
networks:
- production-network
restart: unless-stopped
depends_on:
- rest-proxy
- broker
Assuming that init-user-db.sql
file contains your initialization scripts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With