Rancher 不公开端口

时间:2021-03-26 15:02:21

标签: docker networking iptables rancher

我已设置:Rancher (1.6.30) 和 Docker (18.09.9)。

当我从 docker-compose 创建牧场主集群时:

version: '2'
services:
  mongo:
    image: mongo:4.4.2
    stdin_open: true
    volumes:
    - /var/lib/mongo/data/db:/data/db
    tty: true
    ports:
    - 27017:27017/tcp
  app1:
    image: XX
    stdin_open: true
    tty: true
    ports:
    - 10503:80/tcp
    labels:
      io.rancher.container.pull_image: always
  app2:
    image: XX
    stdin_open: true
    tty: true
    ports:
    - 10504:8080/tcp
  app3:
    image: XX
    stdin_open: true
    tty: true
    ports:
    - 10502:8080/tcp
    - 15502:8500/tcp
    labels:
      io.rancher.container.pull_image: always
  db:
    image: postgres:11.7-alpine
    stdin_open: true
    volumes:
    - /var/lib/postgresql/data:/var/lib/postgresql/data
    tty: true
    ports:
    - 10501:5432/tcp
    labels:
      io.rancher.container.pull_image: always

没有暴露于世界的端口。正如我们可以通过使用 docker ps

看到的

docker ps

虽然,当我在 url 中使用“localhost”时,我可以从容器外部访问服务,但只能从当前机器访问。但是当我尝试从不同的 IP 连接时 - 会超时。

我认为rancher有问题,因为当我手动创建容器时

docker run -p 10503:80 -d 注册表/服务

服务可从任何地方访问,docker ps 在“端口”列中打印绑定。

这是rancher创建docker容器后的iptables:

iptables -L -n --line-numbers -t nat

正如我们所见,没有绑定。

这很奇怪,因为我在其他服务器(相同的牧场主 + docker,相同的应用程序)上也有相同的情况,并且一切正常。

提前致谢

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,在过去的几个小时里尝试了不同的事情,似乎是因为如果你像我一样使用 Debian 10,Rancher 1.6 使用 iptables 来处理一些规则和 iptables-nft(这是从 iptables simlinked)其他规则。 Debian 10 使用 iptables-nft,但在切换回 iptables-legacy 并重新启动后,一切正常:

update-alternatives --set iptables /usr/sbin/iptables-legacy
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
update-alternatives --set arptables /usr/sbin/arptables-legacy
update-alternatives --set ebtables /usr/sbin/ebtables-legacy

来源:https://wiki.debian.org/iptables