如何让主机网络与 docker 群模式一起工作
How do I get host networking to work with docker swarm mode
从最近合并到 docker 的 17.06 候选发布版本的 this PR 开始,我们现在支持使用 swarm 服务的主机网络。但是,在尝试一个非常相似的命令时我看到了一个错误:
$ docker service create --name nginx-host --network host nginx
Error response from daemon: could not find the corresponding predefined swarm network: network host not found
我是 运行 17.06 候选发布者:
$ docker version
Client:
Version: 17.06.0-ce-rc2
API version: 1.30
Go version: go1.8.3
Git commit: 402dd4a
Built: Wed Jun 7 10:07:14 2017
OS/Arch: linux/amd64
Server:
Version: 17.06.0-ce-rc2
API version: 1.30 (minimum version 1.12)
Go version: go1.8.3
Git commit: 402dd4a
Built: Wed Jun 7 10:06:06 2017
OS/Arch: linux/amd64
Experimental: true
我的命令与 docker 现在支持的命令有何不同?
与docker开发者讨论后,此功能需要在升级到17.06后初始化swarm。在 swarm init 运行之前创建的主机和桥接网络不能与节点本地网络一起使用。由于这是一个测试环境,因此重新创建了我的群:
$ docker swarm leave --force
Node left the swarm.
$ docker swarm init
Swarm initialized: current node (***) is now a manager.
...
现在 docker service create
命令起作用了:
$ 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
为了验证,让我们检查容器内的网络接口:
$ 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 ***
...
从最近合并到 docker 的 17.06 候选发布版本的 this PR 开始,我们现在支持使用 swarm 服务的主机网络。但是,在尝试一个非常相似的命令时我看到了一个错误:
$ docker service create --name nginx-host --network host nginx
Error response from daemon: could not find the corresponding predefined swarm network: network host not found
我是 运行 17.06 候选发布者:
$ docker version
Client:
Version: 17.06.0-ce-rc2
API version: 1.30
Go version: go1.8.3
Git commit: 402dd4a
Built: Wed Jun 7 10:07:14 2017
OS/Arch: linux/amd64
Server:
Version: 17.06.0-ce-rc2
API version: 1.30 (minimum version 1.12)
Go version: go1.8.3
Git commit: 402dd4a
Built: Wed Jun 7 10:06:06 2017
OS/Arch: linux/amd64
Experimental: true
我的命令与 docker 现在支持的命令有何不同?
与docker开发者讨论后,此功能需要在升级到17.06后初始化swarm。在 swarm init 运行之前创建的主机和桥接网络不能与节点本地网络一起使用。由于这是一个测试环境,因此重新创建了我的群:
$ docker swarm leave --force
Node left the swarm.
$ docker swarm init
Swarm initialized: current node (***) is now a manager.
...
现在 docker service create
命令起作用了:
$ 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
为了验证,让我们检查容器内的网络接口:
$ 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 ***
...