简体   繁体   English

无法连接与docker一起运行的pgbouncer和postgres

[英]Can't connect pgbouncer and postgres running with docker

So here is the command to start database 所以这是启动数据库的命令

sudo docker run --name mydb -e "POSTGRES_USER=user" -e "POSTGRES_PASSWORD=password" -t -d postgres

Here is dockerfile for pgbouncer 这是pgbouncer的dockerfile

from ubuntu
RUN apt-get update && apt-get -y install pgbouncer
COPY /pgbouncer.ini /etc/pgbouncer/
COPY /userlist.txt /etc/pgbouncer/
EXPOSE 6543

And here is the settings for pgbouncer 这是pgbouncer的设置

[databases]
host = mydb

[pgbouncer]
pool_mode = session
listen_addr = localhost
listen_port = 6543
auth_type = plain
auth_file = userlist.txt
user = postgres

userlist.txt userlist.txt

"user "password" “用户密码”

So the image builds well. 因此图像构建良好。

sudo docker run  -P -p 6543:6543 --name pgbouncer --link mydb:mydb -t leos/pgbouncer pgbouncer /etc/pgbouncer/pgbouncer.ini

I'm starting it with this command and I know that pgbouncer is working, because pgadmin tries to connect to database. 我正在使用此命令启动它,我知道pgbouncer正在运行,因为pgadmin尝试连接到数据库。

And pgbouncer gives me this output (which for some reason doesn't saying anything about whether is pgbouncer connected to database or not). 并且pgbouncer给了我这个输出(由于某种原因,它没有说任何关于pgbouncer是否连接到数据库)。

2014-12-13 12:28:28.937 1 ERROR host: syntax error in connstring
2014-12-13 12:28:28.937 1 LOG File descriptor limit: 524288 (H:1048576), max_client_conn: 100, max fds possible: 110
2014-12-13 12:28:28.937 1 LOG listening on ::1/6543
2014-12-13 12:28:28.937 1 LOG listening on 127.0.0.1:6543
2014-12-13 12:28:28.937 1 LOG listening on unix:/tmp/.s.PGSQL.6543
2014-12-13 12:28:28.937 1 LOG process up: pgbouncer 1.5.4, libevent 2.0.21-stable (epoll), adns: evdns2
2014-12-13 12:29:28.938 1 LOG Stats: 0 req/s, in 0 b/s, out 0 b/s,query 0 us
2014-12-13 12:30:28.939 1 LOG Stats: 0 req/s, in 0 b/s, out 0 b/s,query 0 us
2014-12-13 12:31:28.940 1 LOG Stats: 0 req/s, in 0 b/s, out 0 b/s,query 0 us
2014-12-13 12:32:28.941 1 LOG Stats: 0 req/s, in 0 b/s, out 0 b/s,query 0 us
2014-12-13 12:33:28.941 1 LOG Stats: 0 req/s, in 0 b/s, out 0 b/s,query 0 us

And here is what I can see in pgadmin 以下是我在pgadmin中可以看到的内容

 Error: Error connecting to the server: server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.

This line in config and docker opts are not corelated. config和docker opts中的这一行不是核心。

host = mydb
--link mydb:mydb

You should read about --link usage inside container. 您应该阅读 - 容器内的链接使用情况。 You need update pgbouncer config with real host/port from ENV provided by --link 您需要使用--link提供的ENV中的真实主机/端口更新pgbouncer配置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM