Verifying the Microservice with Consul's DNS

Let's try one more thing - use Consul’s DNS interface from a different container to ping our service. We’ll run a simple Ubuntu container on Node3:

$docker run --dns 172.17.0.1 --dns 8.8.8.8 --dns-search service.consul --rm --name ping_test -it ubuntu

The “--dns” parameter allows us to use a custom DNS server for our container. By default the container will use the same DNS servers as its host. In our case we want it to use the docker bridge interface (172.17.0.1) first and then, if it can not find the host, then to go to 8.8.8.8. Finally, the “dns-search” option makes it easier to query our services. For example, instead of querying for “python-micro-service.service.consul” we can just query for “python-micro-service”. Let’s try to ping our service from the new Ubuntu container:

root@00a70eff5a2e:/# ping -qc 1 python-micro-service
PING python-micro-service.service.consul (172.16.20.184) 56(84) bytes of data.

--- python-micro-service.service.consul ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.430/0.430/0.430/0.000 ms

root@00a70eff5a2e:/# ping -qc 1 python-micro-service
PING python-micro-service.service.consul (172.16.20.94) 56(84) bytes of data.

--- python-micro-service.service.consul ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.056/0.056/0.056/0.000 ms
root@00a70eff5a2e:/# ping -qc 1 python-micro-service
PING python-micro-service.service.consul (172.16.20.132) 56(84) bytes of data.

--- python-micro-service.service.consul ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.481/0.481/0.481/0.000 ms

results matching ""

    No results matching ""