如何确保Docker容器具有所需的网络接口

时间:2018-08-27 07:40:08

标签: docker docker-container docker-network

当我在主机(ubuntu)上运行ifconfig命令时,我看到以下界面

docker0   Link encap:Ethernet  HWaddr 02:42:af:2d:7b:4e
          inet addr:172.17.0.1  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:afff:fe2d:7b4e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:17372371 errors:0 dropped:0 overruns:0 frame:0
          TX packets:18910860 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:3877362521 (3.8 GB)  TX bytes:5648219155 (5.6 GB)

eth0      Link encap:Ethernet  HWaddr 00:50:56:bd:6d:6c
          inet addr:9.113.140.176  Bcast:9.113.140.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:febd:6d6c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:22690545 errors:0 dropped:10 overruns:0 frame:0
          TX packets:4168167 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:5364157575 (5.3 GB)  TX bytes:398826434 (398.8 MB)

eth1      Link encap:Ethernet  HWaddr 00:50:56:a3:7f:17
          inet addr:9.113.140.166  Bcast:9.113.140.255  Mask:255.255.255.0
          inet6 addr: fe80::11ff:7a9c:83ed:f11f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:16962121 errors:0 dropped:10 overruns:0 frame:0
          TX packets:2690 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1214246465 (1.2 GB)  TX bytes:515223 (515.2 KB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:605048269 errors:0 dropped:0 overruns:0 frame:0
          TX packets:605048269 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:137424265344 (137.4 GB)  TX bytes:137424265344 (137.4 GB)

就像我在容器内检查时发现的那样

[AppConnect-Container@772840b42460 /]: ifconfig
eth0      Link encap:Ethernet  HWaddr 02:42:ac:11:00:05
          inet addr:172.17.0.5  Bcast:0.0.0.0  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:16966 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12819 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:14565227 (14.5 MB)  TX bytes:10658766 (10.6 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:984571 errors:0 dropped:0 overruns:0 frame:0
          TX packets:984571 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:187746811 (187.7 MB)  TX bytes:187746811 (187.7 MB)

我甚至希望eth1网络接口在容器内可用。请让我知道如何实现这一目标

1 个答案:

答案 0 :(得分:0)

使用--net=host选项启动容器,您将在容器中拥有主机接口。