6

From this PR that got recently merged into docker's 17.06 release candidate, we now have support for host networking with swarm services. However, trying out a very similar command I'm seeing an error:

$ 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

I'm running the 17.06 release candidate:

$ 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

What's different from my command from what docker now supports?

BMitch
  • 231,797
  • 42
  • 475
  • 450

2 Answers2

7

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 ***
...
BMitch
  • 231,797
  • 42
  • 475
  • 450
1

Yes @dev93, there is a way to create swarm services using host network via docker-compose file (yml).

version: "3.9"
services:  
  nginx:
    image: nginx
    networks:
      - outside

networks:
    outside:
      name: "host"
      external: true

If you came this far and reading this, you'd also like to know that once you spin up your service using host network, you can't be part of the overlay network anymore. When using host, that no other networks are allowed

Kano
  • 11
  • 2
  • 1
    This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/34540164) – pmacfarlane Jun 14 '23 at 19:20
  • Yes, it is an answer to @dev03 question. My aim is not to increase my reputation points, I simply don't care. You delete a piece of non-trivial information that may potentially save someone hours of search, it's on you. – Kano Jun 15 '23 at 06:23
  • An answer is not the correct place to respond to a comment. It is BMitch who has a question needing an answer, not dev03. – pmacfarlane Jun 15 '23 at 06:26
  • Yeah makes sense. – Kano Jun 15 '23 at 06:36