【发布时间】:2020-11-20 20:32:43
【问题描述】:
我用不同的图像制作了两个不同的容器,它们都以相同的 ip 结束,因为我在删除之前的一个后创建了一个,都使用了 postgresql 图像,我无法连接到持有特定 ip 192.168.3.2 的容器,但是从带有 postgres 的容器中,我可以使用该 ip 和 psql 进行连接,但是从另一个容器尝试会导致
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?
但同样的命令会在另一个 postgres 容器上成功。不可达容器的配置为:
listen_addresses = '*'
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
#port = 5432 # (change requires restart)
我认为没问题,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
例如,我无法连接到 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
还有网络ls:
NETWORK ID NAME DRIVER SCOPE
496515e2ff28 bridge bridge local
50b61710b459 host host local
e061da58f729 none null local
我必须指出,直到最近,在我使用 systemctl stop docker 重新启动 docker 服务并随后启动之后,该容器才可以访问。
还有容器
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
从 odoo10 我可以到达其他 postgres 容器,但不是 3.2 的容器,并且两者的 ip 在同一范围内。
可能是什么问题? iptables 不好(我的知识是空的)吗?这可能是一个 docker 错误吗?
【问题讨论】:
-
我应该注意,我尝试使用 postgres 9.4 和 postgres 10 来处理无法访问的容器,当尝试使用 psql 从另一个具有相同范围的 ip 的容器中访问它们时,两者都返回连接被拒绝。
标签: linux postgresql docker centos7 psql