Skip to content
Advertisement

Docker disable restart on-failure

The following situation:

  • I have a Spring Boot Application
  • which runs in a Docker swarm
  • but fails to start because it was not properly configured (a property is missing).
  • It seems to me that the docker swarm always tries to restart the container, but always fails because of the missing property.
  • The restart makes no sense because docker will never be able to start the application unless I fix the missing property.
  • So currently the swarm ends in an endless loop.

Regarding this problem I already read:

My “setup”: The dockerfile:

JavaScript

my YML-file to create the docker service:

JavaScript

What I want to achieve is:

  • If the spring boot application is not able to start because of for example a BeanCreationException or something similar, then I don’t want the docker service to restart endlessly.
  • If I restart the swarm etc. the docker service should restart automatically.

In the docker documentation is written:

If you manually stop a container, its restart policy is ignored until the Docker daemon restarts or the container is manually restarted. This is another attempt to prevent a restart loop.

So I guess that what I want to achieve is not possible with a restart policy.
Questions:

  • but maybe I can write something in my Dockerfile that I achieve my goals?
  • Or am I totally wrong here and misinterpret the documentation?

I am unfortunately not a docker expert and still learning to handle ‘the swarm’.

Advertisement

Answer

Because it does not seem possible what I wanted to achieve, I read the documentation again (https://docs.docker.com/engine/reference/commandline/service_create/) and found the option --restart-max-attempts which will solve my problem with the endless loop.

Advertisement