带有docker compose的postgres给出了FATAL:角色"root"不存在错误 [英] postgres with docker compose gives FATAL: role "root" does not exist error
问题描述
我正在尝试在具有docker桌面的本地Windows机器上使用postgres创建一个简单的演示.
这是我的yaml docker compose文件,名为 img.yaml
:
版本:"3.6"服务:postgres-demo:图片:postgres:11.5-高山container_name:postgres-demo环境:-POSTGRES_USER = postgres-POSTGRES_PASSWORD =欢迎-POSTGRES_DB = conference_app健康检查:测试:["CMD-SHELL","pg_isready -U postgres"]间隔:10s超时:5秒重试:5端口:-5432:5432数量:-.:/var/lib/my_data重启:总是
我正在使用以下命令运行它: docker-compose -f img.yaml up
并获得以下输出:
开始postgres-demo ...完成附加到postgres-demopostgres-demo |2020-02-12 17:07:46.487 UTC [1]日志:侦听IPv4地址"0.0.0.0",端口5432postgres-demo |2020-02-12 17:07:46.487 UTC [1]日志:侦听IPv6地址"::",端口5432postgres-demo |2020-02-12 17:07:46.508 UTC [1]日志:在Unix套接字"/var/run/postgresql/.s.PGSQL.5432"上侦听postgres-demo |2020-02-12 17:07:46.543 UTC [18]日志:数据库系统在UTC 2020-02-12 17:07:10关闭postgres-demo |2020-02-12 17:07:46.556 UTC [1]日志:数据库系统已准备就绪,可以接受连接
然后,使用以下命令将bash打开到容器中: docker exec -it d47056217a97 bash
我想观察容器中的数据库,所以我在bash中运行以下命令: psql \ dt
并得到错误: psql:致命:角色根"不存在
.
尝试使用以下命令创建数据库: psql>创建数据库Conference_App;
会显示错误: psql:FATAL:角色"conference_app"不存在
.
我很困惑我究竟做错了什么?我的Yaml缺少什么吗?
如果未指定 PGUSER
环境变量,则 psql
将假定您要使用当前OS用户作为您的数据库用户名.在这种情况下,您将 root
用作OS用户,并且您将尝试以 root
身份登录,但该用户在数据库中不存在.>
您需要使用 -U Postgres
标志调用 psql
,或者先调用 su-Postgres
另请参见 postgresql文档
I'm trying to create a simple demo with postgres on a local windows machine with docker desktop.
This is my yaml docker compose file named img.yaml
:
version: '3.6'
services:
postgres-demo:
image: postgres:11.5-alpine
container_name: postgres-demo
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=Welcome
- POSTGRES_DB=conference_app
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
ports:
- 5432:5432
volumes:
- .:/var/lib/my_data
restart: always
I'm running it using the command:
docker-compose -f img.yaml up
And get the following output:
Starting postgres-demo ... done
Attaching to postgres-demo
postgres-demo | 2020-02-12 17:07:46.487 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres-demo | 2020-02-12 17:07:46.487 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgres-demo | 2020-02-12 17:07:46.508 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres-demo | 2020-02-12 17:07:46.543 UTC [18] LOG: database system was shut down at 2020-02-12 17:07:10 UTC
postgres-demo | 2020-02-12 17:07:46.556 UTC [1] LOG: database system is ready to accept connections
And then, opening bash into the container with the command:
docker exec -it d47056217a97 bash
I want to watch the databases in container so I run in the bash the command:
psql \dt
And get the error:
psql: FATAL: role "root" does not exist
.
Trying to create the database using the command: psql> create database conference_app;
gives the error: psql: FATAL: role "conference_app" does not exist
.
I'm puzzled. What am I doing wrong? Is my yaml missing something?
If you don’t specify the PGUSER
environment variable, then psql
will assume you want to use the current OS user as your database user name. In this case, you are using root
as your OS user, and you will attempt to log in as root
, but that user doesn’t exist in the database.
You’ll need to either call psql
with the -U Postgres
flag, or su - Postgres
first
See also the postgresql documentation
这篇关于带有docker compose的postgres给出了FATAL:角色"root"不存在错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!