Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Docker角色创建错误-角色不存在_Python_Postgresql_Docker - Fatal编程技术网

Python Docker角色创建错误-角色不存在

Python Docker角色创建错误-角色不存在,python,postgresql,docker,Python,Postgresql,Docker,我是Docker的新手,正在尝试与Postgres合作。然后,我尝试运行python测试用例,这些测试用例适用于其他人,但不适用于我 以下错误告诉我Docker可能正在努力创建foo角色: E sqlalchemy.exc.OperationalError:psycopg2.OperationalError 致命:角色foo不存在 另一个错误: E psycopg2.OperationalError:致命:角色foo不存在 Postgresql版本:mydb=选择版本;: Docker版本 Ve

我是Docker的新手,正在尝试与Postgres合作。然后,我尝试运行python测试用例,这些测试用例适用于其他人,但不适用于我

以下错误告诉我Docker可能正在努力创建foo角色:

E sqlalchemy.exc.OperationalError:psycopg2.OperationalError 致命:角色foo不存在

另一个错误:

E psycopg2.OperationalError:致命:角色foo不存在

Postgresql版本:mydb=选择版本;:

Docker版本

Version 17.06.2-ce-mac27 (19124)
使用此脚本运行Docker:

docker run -p 5432:5432 --env POSTGRES_PASSWORD="bar" --env POSTGRES_USER="foo" --env POSTGRES_DB="mydb" postgres
脚本的输出:如您所见,它表示创建角色

编辑


看起来psycopg2正在尝试本地套接字连接。如果通过TCP连接,您将看到以下异常:

用户foo的密码身份验证失败

以及容器日志中的错误:

FATAL:  password authentication failed for user "foo"
DETAIL:  Role "foo" does not exist.
    Connection matched pg_hba.conf line 95: "host all all all md5"
确保已设置主机连接参数。如果未设置,psycopg2将退回到使用UNIX套接字

编辑:


当传递localhost连接参数时,psycopg2似乎更喜欢UNIX套接字进行连接。如果有两个postgres实例正在运行,一个在侦听UNIX套接字,另一个在侦听TCP端口5432,则当传递url(如p)时,psycopg2将通过UNIX域套接字进行连接ostgresql://localhost:5432.

Teppic,应在何处设置此主机连接参数?这是Docker连接字符串吗?主机参数是否应设置为localhost?基本上,连接字符串应该是这样的:docker run-p 5432:5432-env POSTGRES_PASSWORD=bar-env POSTGRES_USER=foo-env POSTGRES_DB=mydb-env POSTGRES_HOST=localhost POSTGRES您的python测试用例用于连接的参数。是的,它似乎被设置为localhost,这是我想要的,对吗?dsn='dbname=travis user=foo password=bar host=localhost port=5432',database='mydb',user='foo',password='bar',host='localhost',port=5432,connection\u factory=None,cursor\u factory=None async=False,kwargs={},items=['dbname',mydb',user',foo',password bar',host',localhost',port',5432]试试host='127.0.0.1'。我怀疑localhost正在解析为::1,而psycopg2正在退回到套接字连接,因为IPv6地址上没有任何内容正在侦听。我刚刚注意到。。。问题中包含的postgres版本字符串来自本地实例。docker版本应该类似于x86_64-pc-linux-gnu上的PostgreSQL 9.6.5。
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    pg_ctl -D /var/lib/postgresql/data -l logfile start


WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
waiting for server to start....LOG:  could not bind IPv6 socket: Cannot assign requested address
HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG:  database system was shut down at 2017-09-26 21:28:17 UTC
LOG:  MultiXact member wraparound protections are now enabled
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started
 done
server started
CREATE DATABASE

CREATE ROLE


/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*

LOG:  received fast shutdown request
LOG:  aborting any active transactions
LOG:  autovacuum launcher shutting down
waiting for server to shut down....LOG:  shutting down
LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.

LOG:  database system was shut down at 2017-09-26 21:28:19 UTC
LOG:  MultiXact member wraparound protections are now enabled
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS                    NAMES
bbab7eb98fcf        postgres            "docker-entrypoint..."   10 seconds ago      Up 11 seconds              0.0.0.0:5432->5432/tcp   hardcore_wilson
a6a1e2e313b8        postgres            "docker-entrypoint..."   16 minutes ago      Exited (0) 6 minutes ago                            nervous_banach
FATAL:  password authentication failed for user "foo"
DETAIL:  Role "foo" does not exist.
    Connection matched pg_hba.conf line 95: "host all all all md5"