简体   繁体   English

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

[英]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.

相关问题 docker-entrypoint-initdb.d/* 文件在 docker-compose 首次运行时被忽略 - docker-entrypoint-initdb.d/* files ignored on docker-compose first run docker alpine postgres在撰写中不执行docker-entrypoint-initdb.d脚本 - docker alpine postgres in compose not executing docker-entrypoint-initdb.d scripts Docker PostgreSQL - /docker-entrypoint-initdb.d中的脚本无法运行 - Docker PostgreSQL - Scripts in /docker-entrypoint-initdb.d doesn't run docker-compose postgres 在 docker-entrypoint-initdb.d 中运行脚本后重新启动 - docker-compose postgres restart after running scripts in docker-entrypoint-initdb.d 初始化postgres数据库(不使用/docker-entrypoint-initdb.d) - Initialize postgres database (without using /docker-entrypoint-initdb.d) docker-entrypoint-initdb.d 错误解释器:权限被拒绝 - docker-entrypoint-initdb.d bad interpreter: Permission denied 使用 docker-entrypoint-initdb.d 脚本初始化 PostgreSQL 容器 - Initialize PostgreSQL Container with docker-entrypoint-initdb.d script 为什么 docker-entrypoint-initdb.d 中的脚本在数据库开始侦听导致 pg_restore 失败的连接之前运行? - Why are scripts in docker-entrypoint-initdb.d running before the database starts listening for connections causing pg_restore failure? 在Windows上运行Docker映像-docker-entrypoint.sh采购/docker-entrypoint-initdb.d - Running docker images on Windows - docker-entrypoint.sh sourcing /docker-entrypoint-initdb.d docker-entrypoint.sh 忽略 /docker-entrypoint-initdb.d/my.backup - docker-entrypoint.sh ignoring /docker-entrypoint-initdb.d/my.backup
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM