微信公众号:杰夫弹弹看
分类: 云计算
2016-05-28 23:00:08
$ docker inspect -f '{{.State.Pid}}' 63f36fc01b5f 2778 $ pid=2778 $ sudo mkdir -p /var/run/netns $ sudo ln -s /proc/$pid/ns/net /var/run/netns/$pid
$ ip addr show docker0 21: docker0: ... inet 172.17.42.1/16 scope global docker0 ... # Create a pair of "peer" interfaces A and B, # bind the A end to the bridge, and bring it up $ sudo ip link add A type veth peer name B $ sudo brctl addif docker0 A $ sudo ip link set A up # Place B inside the container's network namespace, # rename to eth0, and activate it with a free IP $ sudo ip link set B netns $pid $ sudo ip netns exec $pid ip link set dev B name eth0 $ sudo ip netns exec $pid ip link set eth0 address 12:34:56:78:9a:bc $ sudo ip netns exec $pid ip link set eth0 up $ sudo ip netns exec $pid ip addr add 172.17.42.99/16 dev eth0 $ sudo ip netns exec $pid ip route add default via 172.17.42.1