docker-entrypoint-initdb.d script cannot be executed when I have data binding even though the data doesn't exist
Closed this issue · 0 comments
leohliao commented
Hello, I am encountering a problem where if I bind my volume to /var/lib/postgresql/data, then my initializing script won't execute even if the folder does not exists in the beginning.
image: postgres:16.6-alpine3.20
Here's what my docker compose
version: "3.7"
services:
db:
image: postgres:16.6-alpine3.20
restart: always
environment:
- POSTGRES_DB=db
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- PGPORT=${POSTGRES_PORT}
ports:
- ${POSTGRES_PORT}:${POSTGRES_PORT}
volumes:
- ./my-db:/var/lib/postgresql/data
- ./db-seed.sql:/docker-entrypoint-initdb.d/seed.sql
command: postgres -c 'log_statement=all'
My initializing sql is just to create the database
# db-seed.sql
CREATE DATABASE test_db;
\connect test_db;I am trying to have the initializing sql to run when the my-db folder does not exist.
When I run with one or another then the behavior is as expected, however, if I have both together (and that my my-db folder is deleted and volumes are destroyed) then the initializing sql won't run.
I have tried same thing in postgres 12 and it worked.
Is this an issue with version 16?