![](/img/trans.png)
[英]docker-entrypoint-initdb.d/* files ignored on docker-compose first run
[英]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.