8

I have 2 images that I want to talk to each other via compose's default bridge network, but I also want them to be able to access my host network.

To allow images to talk to each other within compose's default bridge network, I don't need to do anything:

version: '3.4'
services: 
  hello:
   image: hello-world

  world:
    image: hello-world

With the above spec, hello service could reference world service by using the DNS name world

If I wanted hello service to be able to interact with my host machine's network, I could add network_mode: host to the spec.

version: '3.4'
services: 
  hello:
   image: hello-world
   network_mode: host
  world:
    image: hello-world

This allows hello service to access my host machine's network, but can no longer access world via compose's built in DNS. How can I accomplish both?

I've tried creating a custom network, but custom networks can't use the host driver and I cannot use network_mode in combination with networks:

This doesn't work:

version: '3.4'
services: 
  hello:
   image: hello-world
   network_mode: host
   networks:
   - bridge
  world:
    image: hello-world
    networks:
    - bridge

networks:
  test:
    driver: bridge
$ docker-compose up
ERROR: 'network_mode' and 'networks' cannot be combined
Connor Graham
  • 263
  • 3
  • 8

1 Answers1

0

If they're both on your host network, they can talk to each other just like normal applications talk to each other: via localhost. So you don't need the bridge at all.

Itamar Turner-Trauring
  • 3,430
  • 1
  • 13
  • 17