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