简体   繁体   English

使用 /docker-entrypoint-initdb.d 初始化 postgres docker 时不会创建表

[英]Tables are not created when initialize postgres docker with /docker-entrypoint-initdb.d

I am trying to spin a postgres container from docker-compose, copying *.sql files to /docker-entrypoint-initdb.d in order to create the database and the schema.我正在尝试从 docker-compose 旋转 postgres 容器,将 *.sql 文件复制到 /docker-entrypoint-initdb.d 以创建数据库和架构。

The logs from the docker-compose run:来自 docker-compose 运行的日志:

/usr/local/bin/docker-entrypoint.sh: sourcing /docker-entrypoint-initdb.d/02-schema.sql
db_1          | CREATE DATABASE
db_1          | GRANT
db_1          | SET
db_1          | CREATE TABLE
db_1          | CREATE INDEX
db_1          | CREATE TABLE
db_1          | CREATE TABLE

The database is created, but non of the tables is created.已创建数据库,但未创建任何表。 Below is my schema.sql file下面是我的 schema.sql 文件

CREATE DATABASE sample_db OWNER user1;
GRANT ALL PRIVILEGES ON DATABASE sample_db TO user1;


CREATE TABLE PUBLIC.PROFILES(
    USER_ID VARCHAR(50) PRIMARY KEY,
    NAME VARCHAR(50) NOT NULL
);

I used to do the same with my sql container, adding : USE sample_db, but I couldn't find the equivalent postgres command.我曾经对我的 sql 容器做同样的事情,添加:USE sample_db,但我找不到等效的 postgres 命令。

Have you use the POSTGRES_DB environment variable in the docker file?您是否在 docker 文件中使用了 POSTGRES_DB 环境变量? If it isn't set it will use the POSTGRES_USER as database name如果未设置,它将使用 POSTGRES_USER 作为数据库名称

Check the environment variable in the documentation https://hub.docker.com/_/postgres检查文档https://hub.docker.com/_/postgres 中的环境变量

暂无
暂无

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

相关问题 初始化postgres数据库(不使用/docker-entrypoint-initdb.d) - Initialize postgres database (without using /docker-entrypoint-initdb.d) 使用 docker-entrypoint-initdb.d 脚本初始化 PostgreSQL 容器 - Initialize PostgreSQL Container with docker-entrypoint-initdb.d script docker alpine postgres在撰写中不执行docker-entrypoint-initdb.d脚本 - docker alpine postgres in compose not executing docker-entrypoint-initdb.d scripts docker-compose postgres 在 docker-entrypoint-initdb.d 中运行脚本后重新启动 - docker-compose postgres restart after running scripts in docker-entrypoint-initdb.d Docker postgres 不在 docker-entrypoint-initdb.d 中运行 init 文件 - Docker postgres does not run init file in docker-entrypoint-initdb.d Docker-Compose + Postgres:/docker-entrypoint-initdb.d/init.sql:权限被拒绝 - Docker-Compose + Postgres: /docker-entrypoint-initdb.d/init.sql: Permission denied 为什么 postgres 容器在 Gitlab CI 中忽略 /docker-entrypoint-initdb.d/* - Why is postgres container ignoring /docker-entrypoint-initdb.d/* in Gitlab CI 在以前工作的配置中忽略 Postgres 数据库的 /docker-entrypoint-initdb.d 错误 - ignoring /docker-entrypoint-initdb.d error for Postgres database in a configuration that previously worked flyway 无法连接到 docker-entrypoint-initdb.d 脚本中的 postgres 容器 - flyway unable to connect to postgres container within docker-entrypoint-initdb.d script docker-entrypoint-initdb.d 错误解释器:权限被拒绝 - docker-entrypoint-initdb.d bad interpreter: Permission denied
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM