postgresql - 用户未在 postgres docker 映像中创建
问题描述
我有一个 docker 映像,它不接受 yaml docker-compose 文件中定义的用户的凭据。当我转到容器的 docker 控制台并检查用户时,它只列出postgres
. 不知道我错过了什么 - 这是 yaml 文件:
version: '3.8'
services:
db:
container_name: drewreport_container
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: mpassword
POSTGRES_USER: thedrewreport
POSTGRES_DB: thedrewreportdb
ports:
- "5432:5432"
volumes:
- thedrewreportdata:/var/lib/postgresql/data/
volumes:
thedrewreportdata:
有任何想法吗?
解决方案
我无法重现您的问题。运行docker-compose up
,我看到:
Creating network "docker_default" with the default driver
Creating volume "docker_thedrewreportdata" with default driver
Creating docker_client_1 ...
Creating docker_db_1 ...
Creating docker_client_1 ... done
Creating docker_db_1 ... done
Attaching to docker_db_1, docker_client_1
[...]
db_1 | 2021-07-19 23:03:39.676 UTC [1] LOG: database system is ready to accept connections
如果我随后连接psql
,我可以使用您在 中定义的用户名和密码进行身份验证docker-compose.yml
:
# psql -h localhost -U thedrewreport thedrewreportdb
Password for user thedrewreport:
psql (13.3 (Debian 13.3-1.pgdg100+1))
Type "help" for help.
thedrewreportdb=# \du
List of roles
Role name | Attributes | Member of
---------------+------------------------------------------------------------+-----------
thedrewreport | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
thedrewreportdb=#
请注意,您指定的任何卷docker-compose.yml
都将在 adocker-compose down
和 a之间持续存在docker-compose up
,因此,如果您使用不同的凭据建立堆栈,除非您通过运行显式销毁卷,否则这些将永远不会被替换docker-compose down -v
。
如果您在运行时没有看到这样的消息,您可以判断这docker-compose
是在重新使用卷docker-compose up
:
Creating volume "docker_thedrewreportdata" with default driver
推荐阅读
- java - 从android应用程序成功发送数据后,蓝牙打印机不打印数据
- apache-camel - 使用 Apache Camel 进行单元测试
- docker - Kubernetes 部署填充了错误的持久卷
- java - 面板组件在框架卷起后移动
- javascript - 为什么在 JS 示例中输出给出“未定义”而不是“数字”?
- java - 未定义的属性:第 2m8 行 C:\xampp\htdocs\selenium-test\phpwebdriver\WebEleent.php 中的 stdClass::$ELEMENT
- ios - 当应用程序处于后台时,Firebase 通知 [IOS] 不起作用
- sql-server - SQL Server:在单独的表中捕获所有已更改的列
- python - MYSQL - 匹配的返回模式
- laravel-5 - Carbon\Carbon 类的对象无法转换为 int LARAVEL