I'm tryng to use a docker-compose file to mount a posgres container and run two scripts after that. i"m using 'docker-entrypoint-initdb.d' for that.
Here is my docker-compose file:
version: '3.4'
services:
postgres-compose:
image: postgres:11.20-alpine
container_name: postgres11-20
environment:
POSTGRES_DB: "postgres"
POSTGRES_PASSWORD: "123"
ports:
- "5432:5432"
volumes:
- "C:/Docker/postgreslvolume:/var/lib/postgresql/data"
- "./scripts/:/docker-entrypoint-initdb.d/"`
And my scripts and dump file in directory ./scripts are: init-a.sh, init-b.sh, backup.dump.
init-a.sh is like this:
#!/bin/sh
psql -c "CREATE ROLE usertest PASSWORD 'password' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;"
psql -c "CREATE DATABASE databasetest;"
psql --username postgres -c "grant all privileges on databasetest to usertest"
init-b.sh is like this:
#!/bin/sh
pg_restore -p 5432 -U usertest -d databasetest -v "/docker-entrypoint-initdb.d/backup.dump"
exit
My dump file was created on pgadmin.
But its its not working. And this is what docker log show me:
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/backup.dump
2023-05-19 15:05:25
2023-05-19 15:05:25 /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init-a.sh
2023-05-19 15:05:25 /usr/local/bin/docker-entrypoint.sh: line 170: /docker-entrypoint-initdb.d/init-a.sh: cannot execute: required file not found
The first file sets the database and user and the second restore the database. But it tells me that file ins't there. I'm following the script documentation of docker hub for postgres.
I'm expecting to make this dump automatically. I've tryed to change directories and files names. But it's not working at all.