[英]How to make postgresql database connectable from outside of the postgres docker container?
I am using postgres:9.3 docker container from the official docker hub 我正在使用来自官方Docker Hub的Postgres:9.3 Docker容器
https://hub.docker.com/_/postgres/
started the database container with command 使用命令启动数据库容器
docker run -d -e POSTGRES_PASSWORD=mysecretpassword -p 25432:5432 --name osm-database osm-database
and connect to it using docker link from another container(osm-updater) 并使用Docker链接从另一个容器(osm-updater)连接到它
docker run -d --link osm-database --name osm-updater osm-updater
Now I found I can not psql to the database from osm-updater container, get error 现在我发现我无法从osm-updater容器psql到数据库,出现错误
psql: could not connect to server: Connection refused
Is the server running on host "172.17.0.12" and accepting
TCP/IP connections on port 5432?
so I explored the network sockets within the osm-database container with 所以我探索了osm-database容器内的网络套接字
netstat -tulpn
the result 结果
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN
which shows within the osm-database container, the postgres db can only be connected to 127.0.0.1 which is wrong ? 哪个显示在osm-database容器中,postgres db只能连接到127.0.0.1,这是错误的? should be 0.0.0.0:5432 ?
应该是0.0.0.0:5432吗?
so that I could not connect to osm-database from osm-update with command like 这样我就无法使用以下命令从osm-update连接到osm数据库
psql -U postgres -p 5432 -h 172.17.0.12
172.17.0.12 is the ip_address obtained with (docker inspect command) 172.17.0.12是通过(docker inspect命令)获得的ip_address
How could I fix this ? 我该如何解决? How could I change the "local address" column of the network socket
如何更改网络套接字的“本地地址”列
You actually want to use the eth0 of the machine. 您实际上要使用计算机的eth0。 If you are in Linux you can grab it via
ifconfig
and connect to the database on port 25432 as that is the port you are exposing. 如果您使用的是Linux,则可以通过
ifconfig
抓取它,并在端口25432上连接数据库,因为这是您要公开的端口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.