There was a short period of connection refused during docker swarm update

Viewed 84

I have a cluster built by docker swarm, which runs a springboot project. When I upgraded the image that it was running, and task status changed to running, LB directed me to this node, but the response was connection refused, the following is my dockerfile

FROM openjdk:11
COPY target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/app.jar"] 

Now I suspect that the springboot project has not fully started successfully, and the task status become running. I want to know if there is any way to make the Springboot start successfully before the task status becomes running.

1 Answers

Add a healthcheck to the service.

This can be done in the Dockerfile via a

HEALTHCHECK ["CMD","curl http://localhost:8080"]

or via the stack.yml file.

For services with a healthcheck, Docker swarm does not consider the service started until the healthcheck passes and only then adds it to the load balancer.

Related