I looked thru the docs for docker-compose and I see that Version 3 has a deploy restart policy but it's only for swarm. I tried setting restart_policy on my service but got this error:
ERROR: The Compose file './docker-compose.yml' is invalid because: Unsupported config option for services.web: 'restart_policy'
Is there any way to set a restart policy on services created using docker-compose outside of a swarm?
Docker provides restart policies to control whether your containers start automatically when they exit, or when Docker restarts. Restart policies ensure that linked containers are started in the correct order. Docker recommends that you use restart policies, and avoid using process managers to start containers.
Users can type docker ps to check if the restart policy is active; it will be shown as either Up , when the container is up and running, or Restarting when the container is in the restart state.
The docker compose start command is useful only to restart containers that were previously created, but were stopped. It never creates new containers.
It looks like a gap in the documentation
In 3rd version, we can still use "restart" inside services same as before in v.2 (except for deploy into swarm)
version: '3' services: my-service: restart: on-failure:5
https://docs.docker.com/compose/compose-file/compose-file-v3/#restart_policy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With