So I have a docker engine (version 1.12.6, build 78d1802) running in an Ubuntu host.
I created initiated a swarm using
docker swarm init --advertise-addr 192.168.1.2
I have a locally prebuilt image using which I create a service called nodeapp as follows
docker service create --name nodeapp --publish 3000:3000 --replicas 2 node-app-image
Now when I type curl localhost:3000
I get the expected proper response and everything works up to this point.
This document and many others I referred seem to suggest that docker v1.12.x has inbuilt load balancing / routing via either DNS or VIP methods.
So I'm trying to access my service via service name or virtual ip as follows
curl nodeapp:3000
to which I get curl: (6) Could not resolve host: nodeapp
and
curl 10.255.0.6:3000
to which I get curl: (7) Failed to connect to 10.255.0.6 port 3000: Connection timed out
Note that I used the following command to obtain the virtual ip
docker service inspect --format {{.Endpoint.VirtualIPs}} nodeapp
which yields [{boq3g7s47w47q2ej56li9s3dw 10.255.0.6/16}]
Why can't I access my service using the VIP or Service Name even though I can access it using localhost:3000?