Configure Service Discovery

Hey guys,

I’m a begginer with docker swarm, but i set-up my first swarm cluster in two virtual machines, runing ubuntu 16.04 lts, and docker 1.13.

I did my deploy and i have sucess. It’s working! But i have a question, or better, i need a help! I need to use service discovery, because in my job we have to setup an environment with I use the Nginx to WebServer, and this make the location with my containers. Example, if me access: localhost**/Client**, the Nginx direct me to correct service, but i don’t know make this. How i do this? I see in this link https://docs.docker.com/engine/swarm/#feature-highlights, that kubernetes have service discovery, but i don’t now to use this.

Help me, please

If docker service are on the same docker network then they can reference each other using DNS based on service name. Service discovery is built-in to swarm mode (docker service).

e.g.

first create an overlay network for the services to share

$ docker network create -d overlay mynet

Create service of nginx server with 5 replicas (5 container instances with this configuration)

$ docker service create --name nginx --replicas 5 --network mynet nginx:alpine

Create a “curler” service which is on same network and contacts the servers. Note that they are accessible at endpoint nginx. Docker will do L4 load balancing among container instances within the service automatically.

$ docker service create --name curler --network mynet nathanleclaire/curl sh -c 'while true; do curl -si nginx | grep HTTP; sleep 1; done'

(optional: if using --experimental mode) View service logs

$ docker service logs curler

Thank’s Man…

That is amazing…

I go to try more tests…