Removing Services
If we stop a running container, Registrator will notice it and also remove the service from Consul. We can see this by stopping the container running in Node1:
$docker stop d628843108c9
From the logs on Registrator we can see that it will remove the service from Consul
$docker logs 5ad2c811770b
2016/05/13 14:35:15 Starting registrator v7 ...
2016/05/13 14:35:15 Using consul adapter: consul://172.16.20.132:8500
2016/05/13 14:35:15 Connecting to backend (0/0)
2016/05/13 14:35:15 consul: current leader 172.16.20.132:8300
2016/05/13 14:35:15 Listening for Docker events ...
2016/05/13 14:35:15 Syncing services on 2 containers
2016/05/13 14:35:15 ignored: 5ad2c811770b no published ports
2016/05/13 15:32:46 added: c09f762d3283 registrator:service1:5000
2016/05/13 15:53:08 removed: d628843108c9 registrator:service2:5000
Now we are left with two instance of the service.
$curl $HOST_IP:8500/v1/catalog/service/python-micro-service | python -mjson.tool
{
"Address": "172.16.20.94",
"Node": "node3",
"ServiceAddress": "",
"ServiceID": "registrator:service2:5000",
"ServiceName": "python-micro-service",
"ServicePort": 32768,
"ServiceTags": null
},
{
"Address": "172.16.20.184",
"Node": "node2",
"ServiceAddress": "",
"ServiceID": "registrator:service2:5000",
"ServiceName": "python-micro-service",
"ServicePort": 32769,
"ServiceTags": null
}