Consul and Spring Boot services in Docker - not deregistering Consul and Spring Boot services in Docker - not deregistering docker docker

Consul and Spring Boot services in Docker - not deregistering


Consul doesn't automatically deregister services.

See https://groups.google.com/forum/#!topic/consul-tool/slV5xfWRpEE for the hint about the same question. According to that thread you need to either update the config or perform an Agent API call. Since the agent is the source of truth, you shouldn't try to update via Catalog API. See GitHub for details. They also mention at the Google group that you don't necessarily have to deregister services if the node goes down gracefully, but that doesn't seem to be your use case.

Please have a look at Consul not deregistering zombie services for hints about automating the service de-registration using either the api or tools like registrator.


You have mentioned you are using a docker container to run the microservice. Are you trapping the SIGTERM in your entrypoint script in docker container ? If a SIGTERM is sent, the boot application will get it and you will see the below log showing that the microservice is deregistering with Consul.

2017-04-27 09:20:19.854  INFO 6852 --- [on(6)-127.0.0.1] inMXBeanRegistrar$SpringApplicationAdmin : Application shutdown requested.2017-04-27 09:20:19.857  INFO 6852 --- [on(6)-127.0.0.1] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@afb5821: startup date [Thu Apr 27 09:20:00 EDT 2017]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@130c12b72017-04-27 09:20:19.859  INFO 6852 --- [on(6)-127.0.0.1] o.s.c.support.DefaultLifecycleProcessor  : Stopping beans in phase 21474836472017-04-27 09:20:19.863  INFO 6852 --- [on(6)-127.0.0.1] o.s.c.support.DefaultLifecycleProcessor  : Stopping beans in phase 02017-04-27 09:20:19.863  INFO 6852 --- [on(6)-127.0.0.1] o.s.c.c.s.ConsulServiceRegistry          : Deregistering service with consul: xxxxxxxxxxxxx

This blog post discusses this.