所以这是启动数据库的命令
sudo docker run --name mydb -e "POSTGRES_USER=user" -e "POSTGRES_PASSWORD=password" -t -d postgres
这是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
这是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
“用户密码”
因此,图像构建良好。
sudo docker run -P -p 6543:6543 --name pgbouncer --link mydb:mydb -t leos/pgbouncer pgbouncer /etc/pgbouncer/pgbouncer.ini
我正在使用此命令启动它,并且我知道pgbouncer在工作,因为pgadmin尝试连接到数据库。
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
这是我在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.
最佳答案
config和docker opts中的这一行不相关。
host = mydb
--link mydb:mydb
您应该阅读有关容器内部--link用法的信息。
您需要使用--link提供的来自ENV的真实主机/端口来更新pgbouncer配置
关于postgresql - 无法连接使用docker运行的pgbouncer和postgres,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27458908/