ThomasVitale / cloud-native-spring-in-action

🍃 Code samples and projects from the book "Cloud Native Spring in Action - With Spring Boot and Kubernetes" (Manning)
https://www.manning.com/books/cloud-native-spring-in-action
Apache License 2.0
426 stars 257 forks source link

catalog-service fails when started from docker-compose in chapter 6 when all 3 services including config-service #51

Closed rajanjha786 closed 10 months ago

rajanjha786 commented 1 year ago

The code in the Chapter 06 repository for the docker-compose.yml file catalog service uses depends_on on Postgres and config-service. but depends_on by default only waits until the container starts, not until config-service is ready to accept the connections.

I think we have to add the healthchecks for config-service and add condition in depends_on to wait until config-service status is service_healthy

ThomasVitale commented 10 months ago

@rajanjha786 thanks for reporting the issue. It's correct that to have Docker Compose spin up all containers in the correct sequence, a depends_on clause needs to be specified with respect to the Config Service, and a healthcheck clause needs to be included as well.

I haven't covered the Docker health checks in the book on purpose as they put more infrastructural requirements on the application container which is not great from a security or maintainability perspective (e.g. having "curl" installed within the container), but I can see it would have been useful to mention this.

I noted this down and I'll keep it in mind if a second edition of the book happens. Thanks a lot!

Another option would be to increase the max retries for Catalog Service when trying to contact the Config Service, via spring.cloud.config.retry.max-attempts=15.