我有一个数字海洋水滴,我使用带有 ubuntu-18-04-x64 图像的 docker-machine 创建。我使用 docker-compose 为其部署了三个容器,其中一个是 nginx,它的端口 80 和 8080 转发到 0.0.0.0 并因此监听所有接口。
nginx:
image: noumena/nrg-vpp/nginx:latest
ports:
- "80:80"
- "8080:8080"
depends_on:
- engine
- api
防火墙配置为阻止 eth0(DO 公共接口)上的所有流量,docker 的 2376 除外,并在 eth1(DO 私有接口)上打开端口 22、80、8080。
22/tcp on eth1 ALLOW Anywhere
8080/tcp on eth1 ALLOW Anywhere
80/tcp on eth1 ALLOW Anywhere
2376/tcp on eth0 ALLOW Anywhere
Anywhere on eth0 DENY Anywhere
Anywhere on eth1 DENY Anywhere
22/tcp (v6) on eth1 ALLOW Anywhere (v6)
8080/tcp (v6) on eth1 ALLOW Anywhere (v6)
80/tcp (v6) on eth1 ALLOW Anywhere (v6)
2376/tcp (v6) on eth0 ALLOW Anywhere (v6)
Anywhere (v6) on eth0 DENY Anywhere (v6)
Anywhere (v6) on eth1 DENY Anywhere (v6)
但是 docker 转发的端口(80,8080)在 eth0 上仍然可见,任何其他端口在 eth 0 上不可见(例如 22)
17:10 $ telnet public-ip 22
Trying x.x.x.x...
telnet: connect to address x.x.x.x: Operation timed out
telnet: Unable to connect to remote host
17:16 $ telnet public-ip 80
Trying x.x.x.x...
Connected to x.x.x.x.
Escape character is '^]'.
^]
telnet> Connection closed.
17:17 $ telnet public-ip 8080
Trying x.x.x.x...
Connected to x.x.x.x.
Escape character is '^]'.
^]
telnet> Connection closed.
为什么这些端口会开放?转发是否在涉及防火墙之前发生?
我通过将容器限制为仅侦听私有 ip 来解决严重问题,但这很烦人,因为它需要额外的逻辑来查询 droplet 的私有 ip,并且 docker-compose 文件成为模板。如果我可以依靠防火墙来关闭转发的端口,那就简单多了。
有没有人遇到过这种行为?我真的很想了解正在发生的事情。