[英]Postgres docker error: FATAL: password authentication failed for user
I created a Postgres container with docker我用 docker 创建了一个 Postgres 容器
sudo docker run -d \
--name dev-postgres \
-e POSTGRES_PASSWORD=test \
-e POSTGRES_USER=test \
-v ${HOME}/someplace/:/var/lib/postgresql/data \
-p 666:5432 \
postgres
I give the Postgres instance test as a username and password as specified in the doc .我将 Postgres 实例测试作为文档中指定的用户名和密码。
The Postgres port (5432) inside the container is linked to my 666 port on the host.容器内的 Postgres 端口 (5432) 链接到我在主机上的 666 端口。
Now I want to try this out using psql现在我想用 psql 试试这个
psql --host=localhost --port=666 --username=test
I'm prompted to enter the password for user test and after entering test, I get系统提示我输入用户 test 的密码,输入 test 后,我得到
psql: error: FATAL: password authentication failed for user "test"
There are different problems that can cause this有不同的问题可能导致这种情况
The version of Postgres on the host and the container might not be the same主机和容器上的 Postgres 版本可能不一样
If you have to change the docker version of Postgres used, make sure that the container with the new version is not crashing.如果您必须更改使用的 Postgres 的 docker 版本,请确保使用新版本的容器没有崩溃。 Trying to change the version of Postgres while using the same directory for data might cause problem as the directory was initialized with the wrong version.
在使用同一目录存储数据时尝试更改 Postgres 的版本可能会导致问题,因为该目录使用错误的版本初始化。
You can use docker logs [container name]
to debug if it crashes如果崩溃,您可以使用
docker logs [container name]
进行调试
There might be a problem with the volumes used by docker (something with cached value preventing the creation of a new user when env variable change) if you changed the env parameters.如果您更改了 env 参数,则 docker 使用的卷可能存在问题(具有缓存值的东西会在 env 变量更改时阻止创建新用户)。
docker stop $(docker ps -qa) && docker system prune -af --volumes
sudo apt install libpq-dev postgresql-client
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.