[英]Scripts in the /docker-entrypoint-initdb.d folder are ignored
I need to configure Postogres with some SQL commands, but everything I put in the /docker-entrypoint-initdb.d folder doesn't get executed.我需要使用一些 SQL 命令配置 Postogres,但是我放在 /docker-entrypoint-initdb.d 文件夹中的所有内容都没有执行。 I'm using the postgres:9.6 image.
我正在使用 postgres:9.6 图像。
My Dockerfile is as follows:我的Dockerfile如下:
FROM postgres:9.6
COPY init.sql /docker-entrypoint-initdb.d/
USER root
RUN chown postgres:postgres /docker-entrypoint-initdb.d/init.sql
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["postgres"]
I tried multiple commands in init.sql, for example:我在 init.sql 中尝试了多个命令,例如:
CREATE DATABASE db_name;
Finally, this is the part of the yaml file that concerns the database.最后,这是 yaml 文件中与数据库有关的部分。
db:
image: postgres-am
ports:
- target: 5432
published: 5432
protocol: tcp
mode: host
environment:
POSTGRES_PASSWORD: "postgres"
PGDATA: "/var/lib/postgresql/data/pgdata"
volumes:
- db_data:/var/lib/postgresql/data
Postgres only initializes the database if no database is found, when the container starts.如果在容器启动时没有找到数据库,Postgres 只会初始化数据库。 Since you have a volume mapping on the database directory, chances are that a database already exists.
由于您在数据库目录上有卷映射,因此数据库很可能已经存在。
If you delete the db_data
volume and start the container, postgres will see that there isn't a database and then it'll initialize one for you using the scripts in docker-entrypoint-initdb.d
.如果您删除
db_data
卷并启动容器,postgres 将看到没有数据库,然后它将使用docker-entrypoint-initdb.d
中的脚本为您初始化一个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.