[英]Docker PostgreSQL - Scripts in /docker-entrypoint-initdb.d doesn't run
So, I have a docker-compose project with this structure: 所以,我有一个具有这种结构的docker-compose项目:
DockerDev
- docker-compose.yaml
- d-php
- Dockerfile
- scripts-apache
- d-postgresql
- Dockerfile
- scripts
- dev_data_setup.sql
- logs
- pgdata
- www
PHP, Redis, ElasticSearch is OK. PHP,Redis,ElasticSearch都行。 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). 但Postgresql没有运行dev_data_setup.sql,我找到了/dockes-entrypoint-initdb.d的任何不同解决方案(volume,ADD,COPY等)。 I tried to run and sh script and nothing. 我试图运行和sh脚本,没有。
Could you see this docker-compose and Dockerfile and help me? 你能看到这个docker-compose和Dockerfile并帮助我吗? Thanks 谢谢
Dockerfile: Dockerfile:
FROM postgres:latest
ADD ./scripts/dev_data_setup.sql /docker-entrypoint-initdb.d
docker-compose.yaml: 泊坞窗,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
So I found the problem. 所以我发现了问题。
Thanks for your help. 谢谢你的帮助。
Your problem is caused by the way you use ADD
in your Dockerfile: 您的问题是由您在Dockerfile中使用ADD
的方式引起的:
FROM postgres:latest
ADD ./scripts/dev_data_setup.sql /docker-entrypoint-initdb.d
This creates a file called /docker-entrypoint-initdb.d
with the content of the dev_data_setup.sql
file. 这将创建一个名为/docker-entrypoint-initdb.d
的文件,其中dev_data_setup.sql
文件的内容。 What you want is to treat /docker-entrypoint-initdb.d
as a directory. 你想要的是将/docker-entrypoint-initdb.d
视为一个目录。
You should change your ADD
command to one of the following: 您应该将ADD
命令更改为以下之一:
ADD ./scripts/dev_data_setup.sql /docker-entrypoint-initdb.d/
The trailing slash will treat the dest
parameter as a directory. 尾部斜杠将dest
参数视为目录。 Or use 或者使用
ADD ./scripts/dev_data_setup.sql /docker-entrypoint-initdb.d/dev_data_setup.sql
Which will specifically spell out the file name. 其中将具体说明文件名。
Reference: https://docs.docker.com/engine/reference/builder/#/add 参考: 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 at<dest>
. 如果<dest>
不以尾部斜杠结束,则将其视为常规文件,<src>
的内容将写入<dest>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.