postgresql - Docker 文件 postgres 初始模式未执行
问题描述
我将 docker 文件更新到版本 3,但现在没有创建初始模式。我已经尝试过使用不同的卷运行它:docker-compose -f docker-compose.yml up
version: '3'
services:
db-service:
image: postgres:11.2
volumes:
- ./dbscripts/:/docker-entrypoint-initdb.d/
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=sample
ports:
- 5432:5432
解决方案
检查以下两件事:
初始化脚本仅在第一次部署时触发。随后docker-compose ups
,您可能还会在日志中看到以下消息:
db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
要强制重新初始化,您可以擦除数据卷(这将删除条目,而不仅仅是架构)。
要找到路径,只需docker inspect <postgres-container-id>
寻找HostConfig.Binds
脚本一直执行到第一个type "longvarbinary" does not exist
错误。您将需要解决此问题。
db-service_1 | CREATE TABLE
db-service_1 | 2020-07-26 19:29:34.121 UTC [68] ERROR: type "longvarbinary" does not exist at character 68
我在 postgres 容器中打开了一个控制台,您的sample
数据库就在那里,还有一个在脚本中发生 .sql 错误之前创建的表:
docker exec -ti 22b0bb87561f sh
# psql -U postgres
psql (11.2 (Debian 11.2-1.pgdg90+1))
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+------------+------------+-----------------------
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
sample | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
postgres=# \c sample
You are now connected to database "sample" as user "postgres".
sample=# \dt
List of relations
Schema | Name | Type | Owner
--------+----------------------+-------+----------
public | oauth_client_details | table | postgres
(1 row)
推荐阅读
- django - 如何检查 Django 为多租户应用程序生成的 SQL 以确保过滤租户?
- javascript - 如何使用单击的 X 和 Y 坐标移动图像
- django - Django 自定义查询集不返回任何内容
- python - 如何将 Zapier 的 python 节点中的变量输出到电子邮件?
- google-cloud-platform - GCP 外部 http 负载平衡器 502 服务器错误:“failed_to_connect_to_backend”
- android-management-api - 如何通过android管理api阻止chrome中的url
- docker - 使用共享库文件构建 Docker 映像
- java - 将两个垂直的 JSplitPane 放在一个框架 java 上
- java - 我可以使用 Android 智能手机读取 FDX-B RFID 吗?
- mysql - MySQL 与 docker 访问被拒绝