1

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:

Mailo Světel
  • 213
  • 3
  • 10

1 Answers1

0

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
OYPS
  • 58
  • 7