On Failure Max Retry Policy In Docker Compose 2


I’ve using docker compose 2. I want to set restart policy but don’t want to create loop.
For this there is max retry condition. But it seems I can’t use it in version 2.
I get error in Intellij when I want to set max retry like this -restart=on-failure[:2]

Do we need to use version 3 for this?

There is no version 3. Do you mean the version of the compose file? If you go to the docs and search for the restart policy in compose file v2, it doesn’t mention retrying:

Compose file v3 docs does mention “restart_policy” with “max_attempts”

Although I can’t see any mention in the Compose Specs:

Small addition to @rimelek’s answer: restart_policy and max_attempts are only valid for swarm services (regardless if deployed as swarm stack or directly as swarm service), it will be ignored for docker-compose deployments and be an invalid argument for `docker run´.

Oh, you are right.

Docker run supports it according to the docs, it just a different syntax. It actually how Cihad quoted it:

It just not the parameter of docker compose which I forgot to mention.