Skip to content

SQL files under docker-entrypoint-initdb.d are not executed even if data directory is not initialized #1226

Closed

Description

@SimoneGiusso

According to the documentation running docker compose on this yaml file:

services:
  masterdb:
    image: postgres:15.6-alpine
    container_name: primary-server
    ports:
      - 5432:5432
    environment:
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: psw
    volumes:
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
  readonlydb:
    image: postgres:15.6-alpine
    container_name: hot-standby
    ports:
      - 5430:5432
    environment:
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: psw

should initialise:

primary-server with init.sql.

However it does not happen even if the file is correctly mounted:

Screenshot 2024-04-13 at 22 21 18

Ii tried, to delete/re build the images, delete all the volumes but nothing. The init.sql script is not executed.

Activity

  1. tianon commented on Apr 15, 2024

    @tianon
    Member

    Compose works really hard to keep and re-use volumes between runs (including and especially "anonymous" volumes that aren't specified in the file, but are specified in the images in use), which is probably what you're running into.

    Have you tried docker-compose down --volumes and/or docker-compose up --renew-anon-volumes?

  2. locked and limited conversation to collaborators on Apr 15, 2024
  3. converted this issue into a discussion #1227 on Apr 15, 2024
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