Docker and Consul: Pinging services works but curl always returns couldn't connect to host error
<p>I'm trying to deploy multiple services using Docker and use Consul for service discovery.  I've been through various guides and tutorials and I have the following bash script that sets up my Docker containers:</p>

<pre><code>export PRIVATE_IP=XXX.XXX.XXX.XXX
export BRIDGE_IP=XXX.XXX.XXX.XXX
docker run -d --name consul -h $HOSTNAME -p $PRIVATE_IP:8300:8300 -p $PRIVATE_IP:8301:8301 -p $PRIVATE_IP:8301:8301/udp -p $PRIVATE_IP:8302:8302 -p $PRIVATE_IP:8302:8302/udp -p $PRIVATE_IP:8400:8400 -p $PRIVATE_IP:8500:8500 -p $BRIDGE_IP:53:53/udp progrium/consul -server -advertise $PRIVATE_IP -bootstrap
docker run -d --name registrator -v /var/run/docker.sock:/tmp/docker.sock -h $HOSTNAME gliderlabs/registrator consul://$PRIVATE_IP:8500
docker run -d --dns=$BRIDGE_IP --dns 8.8.8.8 --dns-search service.consul -p 3579:3579 --name service1 rcarrington/service1
docker run -d --dns=$BRIDGE_IP --dns 8.8.8.8 --dns-search service.consul -p 3580:3580 --name service2 rcarrington/service2
</code></pre>

<p>This works in so far as I can navigate to the Consul UI and see all the nodes exist and I can also navigate to the services exposed by service1 and service2.  One thing I'm not sure about is that I cannot set the PRIVATE_IP and BRIDGE_IP to anything other than the port the docker server exposes.  The script just errors if for example I try to set the BRIDGE_IP to 172.17.42.1 which is apparently the default.  </p>

<p>The problem is that I want my services to be able to communicate with each other and they don't seem to be able to do so.  If I ping service1 from service2 then I get a response like the following:</p>

<pre><code># ping service1
# PING service1.service.consul (YYY.YYY.YYY.YYY): ZZ data bytes
</code></pre>

<p>This seems to be correct however when I try to use curl to navigate to it's service I get a <code>couldn't connect to host</code> error.  I've tried every combination of host names and IP addresses (including the correct port) with no luck.  Possibly oddly the IP address that ping returns is not the 1 used in the script above.</p>

<p>I'm running the latest Docker-Toolbox on Windows 10.  My service containers are running mono and executing NancyFX self host applications.</p>

<p>I'm assuming I'm doing something wrong in the bash script but I've got no idea what.  Any help would be greatly appreciated.</p>