Docker – How to expose a Docker network to the host machine

dockerdocker-composenetworking

Consider the following docker-compose.yml

version: '2'
services:
    serv1:
        build: .
        ports:
          - "8080:8080"
    links:
      - serv2

    serv2:
        image: redis
        ports:
          - "6379:6379"

I am fowarding the ports to the host in order to manage my services, but the services can access each other simply using the default docker network. For example, a program running on serv1 could access redis:6379 and some DNS magic will make that work. I would like to add my host to this network so that i can access container's ports by their hostname:port.

Best Answer

You can accomplish this by running a dns proxy (like dnsmasq) in a container that is on the same network as the application. Then point your hosts dns at the container ip, and you'll be able to resolve hostnames as if you were in the container on the network.

https://github.com/hiroshi/docker-dns-proxy is one example of this.