![](/img/trans.png)
[英]Initialize PostgreSQL Container with docker-entrypoint-initdb.d script
[英]Docker PostgreSQL - Scripts in /docker-entrypoint-initdb.d doesn't run
所以,我有一个具有这种结构的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都行。 但Postgresql没有运行dev_data_setup.sql,我找到了/dockes-entrypoint-initdb.d的任何不同解决方案(volume,ADD,COPY等)。 我试图运行和sh脚本,没有。
你能看到这个docker-compose和Dockerfile并帮助我吗? 谢谢
Dockerfile:
FROM postgres:latest
ADD ./scripts/dev_data_setup.sql /docker-entrypoint-initdb.d
泊坞窗,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
所以我发现了问题。
谢谢你的帮助。
您的问题是由您在Dockerfile中使用ADD
的方式引起的:
FROM postgres:latest
ADD ./scripts/dev_data_setup.sql /docker-entrypoint-initdb.d
这将创建一个名为/docker-entrypoint-initdb.d
的文件,其中dev_data_setup.sql
文件的内容。 你想要的是将/docker-entrypoint-initdb.d
视为一个目录。
您应该将ADD
命令更改为以下之一:
ADD ./scripts/dev_data_setup.sql /docker-entrypoint-initdb.d/
尾部斜杠将dest
参数视为目录。 或者使用
ADD ./scripts/dev_data_setup.sql /docker-entrypoint-initdb.d/dev_data_setup.sql
其中将具体说明文件名。
参考: https : //docs.docker.com/engine/reference/builder/#/add
如果
<dest>
不以尾部斜杠结束,则将其视为常规文件,<src>
的内容将写入<dest>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.