Postgresql和pgadmin docker容器的问题 [英] Problem with postgresql and pgadmin docker containers
问题描述
我正在尝试将postgresql
和pgadmin4
连接在一起.
pgadmin4
可以正常工作,但是当我尝试创建新服务器时,我遇到两个问题:
I'm trying to connect postgresql
and pgadmin4
work together.
pgadmin4
works fine but when I try to create a new server I have 2 problems:
- 如果
postgres
容器位于不是5432的其他端口上,则无法识别该端口.它显示此错误:could not connect to server: Connection refused Is the server running on host "172.17.0.5" and accepting TCP/IP connections on port 5431?
- 如果
postgres
容器位于端口5432,则错误为FATAL: password authentication failed for user "example"
.
- if the
postgres
container is at other port that is not 5432 it dont recognize that port. It show this error:could not connect to server: Connection refused Is the server running on host "172.17.0.5" and accepting TCP/IP connections on port 5431?
- if the
postgres
container is at port 5432 the error isFATAL: password authentication failed for user "example"
.
我执行此命令来获取postgres
容器:docker run -p 5431:5432 --name postgres2 -e POSTGRES_PASSWORD=ad1234 -d postgres
.
I execute this command to get postgres
container: docker run -p 5431:5432 --name postgres2 -e POSTGRES_PASSWORD=ad1234 -d postgres
.
我尝试跟随stackoverflow中的其他响应,添加此命令-c"listen_addresses='*'"
,我也输入了配置文件,但对我来说没有这项工作.
I try, following other responses in stackoverflow, adding this command -c"listen_addresses='*'"
and I enter in the config file too but noone of this work to me.
希望您能帮助我,谢谢.
Hope you can help me, thanks.
好的,我解决了,这对我来说是一个很大的失败.我正在使用172.17.0.5
(IP容器地址),而我需要使用的连接是172.17.01
(网关).
谢谢您的时间.
Ok I solved, it was a big fail by my part. I was using 172.17.0.5
(the IP container address) and what I need to use to connect is 172.17.01
(the Gateway).
Thanks for you time.
推荐答案
我以这种方式重现了您的方案:
I have reproduce your scenario this way:
# docker run -p 5431:5432 --name postgres2 -e POSTGRES_PASSWORD=ad1234 -d postgres
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d4030c577a24 postgres "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 0.0.0.0:5431->5432/tcp postgres2
# sudo -u postgres psql -h localhost -p 5431
could not change directory to "/root": Permission denied
Password:
psql (10.5, server 11.2 (Debian 11.2-1.pgdg90+1))
WARNING: psql major version 10, server major version 11.
Some psql features might not work.
Type "help" for help.
postgres=# CREATE DATABASE mytestdb;
CREATE DATABASE
postgres=# \q
现在为pgadmin启动docker并能够连接到postgresql:
Now starting docker for pgadmin and being able to connect to postgresql:
docker run -p 80:80 --link postgres2 -e "PGADMIN_DEFAULT_EMAIL=user@domain.com" -e "PGADMIN_DEFAULT_PASSWORD=SuperSecret" -d dpage/pgadmin4
使用上述命令,您可以将postgres2泊坞窗链接到pgadmin泊坞窗,然后在pgadmin4上创建连接时,应使用:
With the above command you can link the postgres2 docker to the pgadmin docker and then on creating a connection on pgadmin4 you should use:
- 主机名/地址:postgres2
- 端口:5432
- 维护数据库:postgres
- 用户名:postgres
那样,我已经从pgadmin4连接到Postgres
with that, I've connected to Postgres from pgadmin4
据我所知,docker PostgreSQL默认带有仅本地主机连接,如果要添加远程连接,则应在postgresql.conf中添加"listen_addresses ='*'"
As far as I know, docker PostgreSQL comes by default with localhost only connection and if you want to add remote connection you should add "listen_addresses = '*'" to postgresql.conf
这篇关于Postgresql和pgadmin docker容器的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!