Skip to content

docker-entrypoint-initdb.d script cannot be executed when I have data binding even though the data doesn't exist #1327

Description

@leohliao

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions