2

In my docker-compose.yaml I am saying to alway restart app service

 app: build: . image: app:latest ports: - 3000:3000 restart: always volumes: - "./:/usr/src/app" 

This works, but in case of permanent error (eg. server is running some other way, …), the service keeps trying to start. Is there way to limit number of attempts to restart the service?

Here is a demo code, which I created to take us on same page:

1 Answer 1

1

You can find the answer in the docker compose reference description here:

https://docs.docker.com/compose/compose-file/

You can apply a condition to the restart block inside of the compose file. In your case something like:

restart_policy: condition: on-failure max-attempts: 3 
3
  • It seems to me what you refer to, is for docker stacks. I'll try it at home, but I think this is ignored by docker compose. Commented Apr 8, 2020 at 17:45
  • @MailoSvětel Did you try the solution? Commented Apr 11, 2020 at 7:44
  • Sorry for the delay, I was on other stuff. It works just as I suspected. Check the updated question for links to demo code Commented Apr 12, 2020 at 12:39

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.