Docker Community Forums

Share and learn in the Docker community.

Use host network for swarm container

Hi, according to this, starting on Docker 17.06 I can use a host network for a swarm service. I tried adding network_mode to a service in my config file but it gets ignored.

Ignoring unsupported options: network_mode

Isn’t that the correct option?

My service is defined along these lines:

version: ‘3.4’
image: boldt/coturn
hostname: xxx
network_mode: host

replicas: 1
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s

Hey @phowat
this is a known issue
so host network_mode cannot be used in docker swarm.
please read below link

Hi @nishitmv, thanks for the reply. My original question was not phrased in the best way, let me try to clarify.

I managed to get it working by creating the service manually, outside my compose file, with the following command:

docker service create --env-file ./coturn.env
–mount type=bind,source=xxx.pem,destination=/etc/ssl/turn_server_cert.pem
–mount type=bind,source=xxx.pem,destination=/etc/ssl/turn_server_pkey.pem
–replicas 1 --name coturn --network host boldt/coturn

So, is there an option to be used in the compose file that does the same as the --network option from the command line ?

So you can use networks option like this

version: '3.4'

    image: "nginx:alpine"
      - outside

      name: "host"

it will attach the container to host network
please read below for more info about it


when using this host network, service name is not resolving inside the container. And also network alisa is not working. Any idea why so?

I am using docker stack deploy