[英]Postgres Docker container does not run create SQL script
docker-compose.yml
version: '3'
services:
db:
image: "postgres"
build: .
ports:
- "5432:5432"
env_file:
- database.env
Dockerfile
FROM postgres:9.3
ADD CreateDB.sql /docker-entrypoint-initdb.d/
CreateDB.sql
CREATE TABLE data_actions (
username VARCHAR NOT NULL,
json_payload VARCHAR NOT NULL,
cache_id VARCHAR,
action_timestamp TIMESTAMP
)
database.env
DOCKER_USER=docker
DOCKER_DB=docker
DOCKER_PASSWORD=docker
These are the files I'm using to create this container.这些是我用来创建这个容器的文件。 I've verified that the CreateDB.sql script is copied into the container and is in the correct location.我已验证 CreateDB.sql 脚本已复制到容器中并且位于正确的位置。 When I build and run the container and check pgAdmin, there are no tables in the docker database.当我构建并运行容器并检查 pgAdmin 时,docker 数据库中没有表。 I feel like I'm missing something obvious here?我觉得我在这里遗漏了一些明显的东西?
UPDATE Here are the logs from startup ->更新这里是启动的日志->
LOG: database system was interrupted; last known up at 2020-12-23 18:21:18 UTC
LOG: database system was not properly shut down; automatic recovery in progress
LOG: record with zero length at 0/17A7030
LOG: redo is not required
LOG: MultiXact member wraparound protections are now enabled
LOG: autovacuum launcher started
LOG: database system is ready to accept connections
LOG: received smart shutdown request
LOG: autovacuum launcher shutting down
The problem is that you have misnamed your environment variables.问题是您错误地命名了环境变量。 The postgres image expects the environment names to begin with POSTGRES_
(so, POSTGRES_DB
, POSTGRES_USER
, etc). postgres 映像要求环境名称以POSTGRES_
开头(例如POSTGRES_DB
、 POSTGRES_USER
等)。
After renaming things in database.env
so that I have:重命名database.env
中的内容后,我有:
POSTGRES_USER=docker
POSTGRES_DB=docker
POSTGRES_PASSWORD=docker
I can start your compose stack and then:我可以启动您的撰写堆栈,然后:
$ docker-compose exec db psql -U docker
psql (9.3.25)
Type "help" for help.
docker=# \c docker
You are now connected to database "docker" as user "docker".
docker=# \dt
List of relations
Schema | Name | Type | Owner
--------+--------------+-------+--------
public | data_actions | table | docker
(1 row)
docker=#
With your original database.env
, Postgres would have created your data_actions
table in the default postgres
database.使用您的原始database.env
,Postgres 将在默认postgres
数据库中创建您的data_actions
表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.