Postgres: Scripts in /docker-entrypoint-initdb.d doesn't run

Created on 2 Nov 2016  路  2Comments  路  Source: docker-library/postgres

So, I have a docker-compose project with this structure:

- docker-compose.yaml
- d-php
  - Dockerfile
  - scripts-apache
- d-postgresql
  - Dockerfile
  - scripts
    - dev_data_setup.sql
- logs
- pgdata
- www

PHP, Redis, ElasticSearch is OK. But Postgresql doesn't run dev_data_setup.sql, with any diferent solutions to /dockes-entrypoint-initdb.d that I found (volume, ADD, COPY, etc). I tried to run and sh script and nothing.

Could you see this docker-compose and Dockerfile and help me? Thanks

Dockerfile:

FROM postgres:latest
ADD ./scripts/dev_data_setup.sql /docker-entrypoint-initdb.d

docker-compose.yaml:

version: '2'
services:
  php:
    build: ./d-php/
    hostname: www.domain.com
    ports:
      - "80:80"
    volumes:
      - ./www:/var/www/html
      - ./d-php/scripts-apache2/apache2.conf:/etc/apache2/apache2.conf
      - ./d-php/scripts-apache2/web.conf:/etc/apache2/sites-enabled/web.conf
      - ./d-php/scripts-apache2/webservice.conf:/etc/apache2/sites-enabled/webservice.conf
      - ./logs:/var/log/apache2
    links:
      - db
      - redis
      - elasticsearch
  db:
    build: ./d-postgresql/
    volumes:
      - ./pgdata:/pgdata
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - PGDATA=/pgdata
  redis:
    image: redis:latest
  elasticsearch:
    image: elasticsearch:2.4.1

Most helpful comment

All 2 comments

@rodrigosaraiva I'm guessing you've discovered it for yourself, but docker-compose works very hard to ensure that your volumes are persisted between recreations of the containers, so you likely had a pre-initialized database in your postgres container which was then re-used, causing your SQL script to not be executed

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tjamet picture tjamet  路  4Comments

qwang07 picture qwang07  路  4Comments

AnatoliyTishaevTR picture AnatoliyTishaevTR  路  3Comments

Enelar picture Enelar  路  4Comments

andrewvo148 picture andrewvo148  路  3Comments