Docker 网络(五)——容器网络命名空间

5 容器网络命名空间

ubuntu@ubuntu:~$ docker network ls 
NETWORK ID          NAME                DRIVER
0343830c6572        bridge              bridge              
de6616e5b5e4        host                host                
a9968713e917        none                null 

可以使用 --net 指定想要在容器上使用的网络。

容器不加载任何网络命名空间 --net=none

ubuntu@ubuntu:~$ docker run -it --rm --net=none ubuntu:14.04 bash
root@264e46995158:/# ip -d link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0 

容器使用 host 命名空间 --net=host

ubuntu@ubuntu:~$ docker run -it --rm --net=host ubuntu:14.04 bash
root@ubuntu:/# ip -d link show
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0 
2: eth0:  mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:4d:a8:3c brd ff:ff:ff:ff:ff:ff promiscuity 0 
3: eth1:  mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:eb:24:7f brd ff:ff:ff:ff:ff:ff promiscuity 0 
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default 
    link/ether 02:42:da:dc:5d:c4 brd ff:ff:ff:ff:ff:ff promiscuity 0 
    bridge 

跟宿主机相同的网络接口

默认使用 –net=bridge

ubuntu@ubuntu:~$ docker run -it --rm --net=bridge ubuntu:14.04 bash
root@50948e11157f:/# ip -d link show
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0 
83: eth0:  mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff promiscuity 0 
    veth 

你可能感兴趣的:(Docker)