Docker PostgreSQL - Scripts in / docker -entrypoint-initdb.d do not run

So, I have a project creating dockers with this structure:

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

PHP, Redis, ElasticSearch are fine. But Postgresql does not start dev_data_setup.sql with any of the various / dockes -entrypoint-initdb.d solutions 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 
+7
docker postgresql docker-compose
source share
2 answers

So, I have found a problem. First: my sql script was trying to recreate the postgres user. then dockedev_db came out. Secondly: I needed to remove all the images associated with db, using docker-compose, run the script again.

Thank you for your help.

+1
source share

Your problem is caused by the way you use ADD in the Docker file:

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

Creates a file called /docker-entrypoint-initdb.d with the contents of the dev_data_setup.sql file. You want to treat /docker-entrypoint-initdb.d as a directory.

You must change the ADD command to one of the following values:

 ADD ./scripts/dev_data_setup.sql /docker-entrypoint-initdb.d/ 

The trailing slash will treat the dest parameter as a directory. Or use

 ADD ./scripts/dev_data_setup.sql /docker-entrypoint-initdb.d/dev_data_setup.sql 

What exactly will the file name indicate.

Link: https://docs.docker.com/engine/reference/builder/#/add

If <dest> does not end with a trailing slash, it will be considered a regular file, and the contents of <src> will be written to <dest> .

0
source share

All Articles