[英]Unable to connect to postgres container from within container in docker
I made two different container with different images, both ended with the same ip as i create one afte deleting the previus one, both used a postgresql image and i was unable to connect to the container holding that specific ip 192.168.3.2, but from within the container with postgres i could connect using that ip with psql, but trying from another container resulted in I made two different container with different images, both ended with the same ip as i create one afte deleting the previus one, both used a postgresql image and i was unable to connect to the container holding that specific ip 192.168.3.2, but from within我可以使用带有 psql 的 ip 连接带有 postgres 的容器,但尝试从另一个容器导致
root@23c9e6ee234c:/# psql -h 192.168.3.2 -U odoo -W -d postgres -p 5432
Password for user odoo:
psql: could not connect to server: Connection refused
Is the server running on host "192.168.3.2" and accepting
TCP/IP connections on port 5432?
But the same command would succeed with a another postgres container.但同样的命令会在另一个 postgres 容器上成功。 The config of the unreachable container is:
无法访问的容器的配置是:
listen_addresses = '*'
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
#port = 5432 # (change requires restart)
i think its ok, and the ip tables (generated by docker and not modified by me are)我认为还可以,并且 ip 表(由 docker 生成且未经我修改)
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere
Chain FORWARD (policy DROP)
target prot opt source destination
DOCKER-ISOLATION all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain DOCKER (1 references)
target prot opt source destination
ACCEPT tcp -- anywhere 192.168.3.11 tcp dpt:8069
ACCEPT tcp -- anywhere 192.168.3.15 tcp dpt:8069
ACCEPT tcp -- anywhere 192.168.3.10 tcp dpt:8072
ACCEPT tcp -- anywhere 192.168.3.10 tcp dpt:8069
ACCEPT tcp -- anywhere 192.168.3.10 tcp dpt:ssh
ACCEPT tcp -- anywhere 192.168.3.14 tcp dpt:8072
ACCEPT tcp -- anywhere 192.168.3.14 tcp dpt:8069
ACCEPT tcp -- anywhere 192.168.3.14 tcp dpt:ssh
ACCEPT tcp -- anywhere 192.168.3.7 tcp dpt:8072
ACCEPT tcp -- anywhere 192.168.3.7 tcp dpt:8069
ACCEPT tcp -- anywhere 192.168.3.7 tcp dpt:ssh
ACCEPT tcp -- anywhere 192.168.3.9 tcp dpt:8072
ACCEPT tcp -- anywhere 192.168.3.9 tcp dpt:ssh
ACCEPT tcp -- anywhere 192.168.3.9 tcp dpt:8069
ACCEPT tcp -- anywhere 192.168.3.13 tcp dpt:hello-port
ACCEPT tcp -- anywhere 192.168.3.13 tcp dpt:mysql
ACCEPT tcp -- anywhere 192.168.3.13 tcp dpt:https
ACCEPT tcp -- anywhere 192.168.3.13 tcp dpt:http
ACCEPT tcp -- anywhere 192.168.3.13 tcp dpt:ssh
ACCEPT tcp -- anywhere 192.168.3.6 tcp dpt:postgres
ACCEPT tcp -- anywhere 192.168.3.3 tcp dpt:8071
ACCEPT tcp -- anywhere 192.168.3.3 tcp dpt:8069
ACCEPT tcp -- anywhere 192.168.3.3 tcp dpt:ipp
ACCEPT tcp -- anywhere 192.168.3.3 tcp dpt:ssh
ACCEPT tcp -- anywhere 192.168.3.4 tcp dpt:8071
ACCEPT tcp -- anywhere 192.168.3.4 tcp dpt:8069
ACCEPT tcp -- anywhere 192.168.3.4 tcp dpt:ipp
ACCEPT tcp -- anywhere 192.168.3.4 tcp dpt:ssh
ACCEPT tcp -- anywhere 192.168.3.2 tcp dpt:postgres
ACCEPT tcp -- anywhere 192.168.3.2 tcp dpt:ssh
Chain DOCKER-ISOLATION (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere
For instance, i cant connect to 192.168.3.6, but no to 3.2, and my docker version is:例如,我无法连接到 192.168.3.6,但无法连接到 3.2,而我的 docker 版本是:
Client:
Version: 17.04.0-ce
API version: 1.28
Go version: go1.7.5
Git commit: 4845c56
Built: Mon Apr 3 18:01:50 2017
OS/Arch: linux/amd64
Server:
Version: 17.04.0-ce
API version: 1.28 (minimum version 1.12)
Go version: go1.7.5
Git commit: 4845c56
Built: Mon Apr 3 18:01:50 2017
OS/Arch: linux/amd64
Experimental: false
And the network ls:和网络 ls:
NETWORK ID NAME DRIVER SCOPE
496515e2ff28 bridge bridge local
50b61710b459 host host local
e061da58f729 none null local
I must point that the container used to be reachable until recently, after i restarted the docker service with systemctl stop docker and initiated afterwards.我必须指出,直到最近,在我使用 systemctl stop docker 重新启动 docker 服务并随后启动之后,该容器才可以访问。
And the containers还有容器
3198ba01cb43 postgres:9.4 "docker-entrypoint..." 3 years ago Up 8 minutes 0.0.0.0:8122->22/tcp, 0.0.0.0:8132->5432/tcp educosal_db
23c9e6ee234c ubuntu "/bin/bash" 3 years ago Up 3 hours 0.0.0.0:8069->8069/tcp, 0.0.0.0:2022->22/tcp, 0.0.0.0:2631->631/tcp, 0.0.0.0:2071->8071/tcp odoo10
from the odoo10 i could reach other postgres containers, but not the one with 3.2, and both have ip in the same range.从 odoo10 我可以到达其他 postgres 容器,但不是 3.2 的容器,并且两者的 ip 在同一范围内。
What could be the problem?可能是什么问题呢? Are the iptables bad (of which my knowledge is null)?
iptables 不好(我的知识是空的)吗? Could this be a docker bug?
这可能是 docker 错误吗?
Postgres 9.4 utilizes a different way to add database access variables, then what 9.5 has. Postgres 9.4 使用不同的方式添加数据库访问变量,然后是 9.5。
Maybe your Docker Engine version realizes it's 9.4 and Postgres 9.5 has another format to add database access variables.也许您的 Docker 引擎版本意识到它是 9.4,而 Postgres 9.5 有另一种格式来添加数据库访问变量。
This link has more information on what my train of thought is after reading your question.在阅读您的问题后,此链接包含有关我的思路的更多信息。 Docker Hub Docs
Docker 集线器文档
Disclosure: I have only taken courses on Docker.披露:我只上过 Docker 的课程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.