繁体   English   中英

/docker-entrypoint-initdb.d 文件夹中的脚本被忽略

[英]Scripts in the /docker-entrypoint-initdb.d folder are ignored

我需要使用一些 SQL 命令配置 Postogres,但是我放在 /docker-entrypoint-initdb.d 文件夹中的所有内容都没有执行。 我正在使用 postgres:9.6 图像。

我的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"]

我在 init.sql 中尝试了多个命令,例如:

CREATE DATABASE db_name;

最后,这是 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 只会初始化数据库。 由于您在数据库目录上有卷映射,因此数据库很可能已经存在。

如果您删除db_data卷并启动容器,postgres 将看到没有数据库,然后它将使用docker-entrypoint-initdb.d中的脚本为您初始化一个。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM