跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[Docker] 有关 docker 默认 iptables 规则的请教

发表于

背景: 宿主机 IP 为 10.0.0.1 ,容器部署在宿主机的默认网桥上,容器 A 的 ip 为 172.17.0.2 ,容器 B 的 ip 为 172.17.0.3 宿主机的端口 50000 映射到容器 A 中 已知现象: 在外部 PC 上可以通过 telnet 10.0.0.1 50000 访问到容器 A 的 50000 端口 在宿主机上可以通过 telnet 10.0.0.1 50000 访问到容器 A 的 50000 端口 在宿主机上可以通过 telnet 172.17.0.2 50000 访问到容器 A 的 50000 端口 在容器 B 中,可以通过 telnet 172.17.0.2 50000 访问到容器 A 的 50000 端口 问题是: 在容器 B 中,无法通过 telnet 10.0.0.1 50000 访问到容器 A 的 50000 端口

iptables 表项如下

Chain PREROUTING (policy ACCEPT 6203 packets, 511K bytes)
 pkts bytes target     prot opt in     out     source               destination
   52  3088 LOG        tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:3128 LOG flags 0 level 4 prefix "PREROUTING: "
 4215  189K DOCKER     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ADDRTYPE match dst-type LOCAL

Chain DOCKER (2 references)
 pkts bytes target     prot opt in     out     source               destination
    3   180 RETURN     all  --  docker0 *       0.0.0.0/0            0.0.0.0/0
   49  2964 RETURN     all  --  br-9950295a8b77 *       0.0.0.0/0            0.0.0.0/0
    2    88 DNAT       tcp  --  !br-9950295a8b77 *       0.0.0.0/0            0.0.0.0/0            tcp dpt:8800 to:172.16.0.88:80
   10   568 DNAT       tcp  --  !docker0 *       0.0.0.0/0            0.0.0.0/0            tcp dpt:50000 to:172.17.0.2:50000

从规则来看,理解是 docker0 中发来的包在命中 DNAT 规则前就 RETURN 了,为什么会这样呢,是鼓励容器网络中互访应该直接使用容器自身的 IP 吗?

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.