How do I get host networking to work with docker swarm mode

China☆狼群 提交于 2019-12-05 11:20:53

After discussing with the docker devs, this feature needs swarm to be initialized after the upgrade to 17.06. Host and bridge networks created before the swarm init runs cannot be used with the node-local networks. Since this was a test environment, recreated my swarm with:

$ docker swarm leave --force
Node left the swarm.

$ docker swarm init
Swarm initialized: current node (***) is now a manager.

...

Now the docker service create command works:

$ docker service create --name nginx-host --network host nginx
i83udvgk0qga0k7toq4v7kh0x

$ docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE                                                                                             PORTS
i83udvgk0qga        nginx-host          replicated          1/1                 docker.io/library/nginx@sha256:41ad9967ea448d7c2b203c699b429abe1ed5af331cd92533900c6d77490e0268

To verify, lets check the network interfaces inside the container:

$ docker ps | grep nginx
7024a2764b46        nginx               "nginx -g 'daemon ..."   16 hours ago        Up 16 hours                             nginx-host.1.i2blydombywzhz9zy06j8wrzf

$ docker exec 702 ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether ***
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether ***
...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!