小编Lui*_*igi的帖子

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

我需要使用一些 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"]
Run Code Online (Sandbox Code Playgroud)

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

CREATE DATABASE db_name;
Run Code Online (Sandbox Code Playgroud)

最后,这是 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
Run Code Online (Sandbox Code Playgroud)

postgresql docker dockerfile docker-compose

6
推荐指数
1
解决办法
8247
查看次数

标签 统计

docker ×1

docker-compose ×1

dockerfile ×1

postgresql ×1