Use host networking and additional networks in docker compose Use host networking and additional networks in docker compose docker docker

Use host networking and additional networks in docker compose


expose in docker-compose does not publish the port on the host. Since you probably don't need service linking anymore (instead you should rely on Docker networks as you do already), the option has limited value in general and seems to provide no value at all to you in your scenario.

I suspect you've come to using it by mistake and after realizing that it didn't seem to have any effect by itself, stumbled upon the fact that using the host network driver would "make it work". This had nothing to do with the expose property, mind you. It's just that the host network driver lets contained processes bind to the host network interface directly. Thanks to this, you could reach the API gateway process from the outside. You could remove the expose property and it would still work.

If this is the only reason why you picked the host network driver, then you've fallen victim of the X-Y problem:

(tl;dr)You should never need to use the host network driver in normal situations, the default bridge network driver works just fine. What you're looking for is the ports property, not expose. This sets up the appropriate port forwarding behind the scenes.


In docker 1.13 you should be able to create a service to bridge between the two networks. I'm using something similar to fix another problem and I think this could also help here:

docker service create \--name proxy \--network proxy \--publish mode=host,target=80,published=80 \--publish mode=host,target=443,published=443 \--constraint 'node.hostname == myproxynode' \--replicas 1 \letsnginx


I would try this :

1/ Find the host networkdocker network ls

2/ Use this dockercompose file

     services:          ms1:              ports:                  - "13010"              networks:                  - service          apigateway:              networks:                  - front                  - service      networks:          front:          service:              external:                  name: "<ID of the network>"