That does answer on a per service/container, sort of … that part of the documentation doesn’t give a clear example of where to use those parameters. It just lists the parameters as if they are floating around in the file “somewhere”.
and more importantly
That doesn’t explain how to have the whole definition in the compose restart itself in the same way as when docker-compose up was run originally. There are things that defined only in the docker-compose.yml file. How are those handled?
For one example:
What is controlling the depends_on references to make sure the services/containers that are depended on start first and then the ones that depend on start after but not before - as is defined in the docker-compose.yml but is not defined for the container on its own.
Does that not work for you if you test out a similar addition in your environment?
Regarding 2) I would simply expect declarations as depends_on: to work just as it did before you add restart: So in the example given above a natural consequence after a restart would be that the dependent services db and redis will be started before web. Something similar should implicitly be true for volumes and networks your services refer to.
Sorry to necro this thread, but I needed an answer to this very question.
After trying this, I found I had to add restart: always to the redis: section as well to make sure it came up. With just depends_on: redis and restart: always in the web: section, the apache container would restart after a reboot, but redis wouldn’t.
With docker-compose, the “restart:” node is a direct child node of a specific service, a sibling of “image:”
For Swarm stack deploymets, the “restart_policy:” node is a child node of “deploy:”, which itself is a sibling of “image:”