有没有办法告诉docker只将转发的端口绑定到IPv4接口?
我在Digital Ocean上运行了一台禁用IPv6的机器:
# echo '1' > /proc/sys/net/ipv6/conf/lo/disable_ipv6 # echo '1' > /proc/sys/net/ipv6/conf/lo/disable_ipv6 # echo '1' > /proc/sys/net/ipv6/conf/all/disable_ipv6 # echo '1' > /proc/sys/net/ipv6/conf/default/disable_ipv6 # /etc/init.d/networking restart
ifconfig报告没有启用IPv6的接口:
# ifconfig docker0 Link encap:Ethernet HWaddr 00:00:00:00:00:00 inet addr:172.17.42.1 Bcast:0.0.0.0 Mask:255.255.0.0 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:1372 errors:0 dropped:0 overruns:0 frame:0 TX packets:7221 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:88091 (88.0 KB) TX bytes:10655750 (10.6 MB) eth0 Link encap:Ethernet HWaddr 04:01:08:c1:b1:01 inet addr:198.XXX.XXX.XXX Bcast:198.199.90.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:97602 errors:0 dropped:4 overruns:0 frame:0 TX packets:15362 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:141867997 (141.8 MB) TX bytes:1376970 (1.3 MB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) lxcbr0 Link encap:Ethernet HWaddr 9e:51:04:ed:13:d4 inet addr:10.0.3.1 Bcast:10.0.3.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
当我启动一个新的docker容器并要求它在容器中将8000转发到8000时,它只在IPv6接口上执行.有没有办法让它只绑定到IPv4接口?
# docker run -p 8000:8000 -i -t colinsurprenant/ubuntu-raring-amd64 /bin/bash # lsof -OnP | grep LISTEN sshd 1275 root 3u IPv4 ... TCP *:22 (LISTEN) sshd 1275 root 4u IPv6 ... TCP *:22 (LISTEN) dnsmasq 2975 lxc-dnsmasq 7u IPv4 ... TCP 10.0.3.1:53 (LISTEN) docker 9629 root 7u IPv6 ... TCP *:8000 (LISTEN) docker 9629 9630 root 7u IPv6 ... TCP *:8000 (LISTEN) docker 9629 9631 root 7u IPv6 ... TCP *:8000 (LISTEN) docker 9629 9632 root 7u IPv6 ... TCP *:8000 (LISTEN) docker 9629 9633 root 7u IPv6 ... TCP *:8000 (LISTEN) docker 9629 9634 root 7u IPv6 ... TCP *:8000 (LISTEN) docker 9629 9698 root 7u IPv6 ... TCP *:8000 (LISTEN)
解决方法
我遇到了同样的问题:
使用以下命令编辑/etc/modprobe.d/blacklist.conf:
blacklist ipv6
和/ etc / default / grub:
GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 console=ttyS0"
然后update-grub并重启.