When you initially run a Docker container from an image you can specify the option:
--restart="always"
This ensures that the container is always restarted by the Docker daemon if for some reason it stops. So you could run a container like so:
docker run --restart="always" <IMAGE>
Also you can restart an existing Docker container by specifying its container ID, i.e.:
docker start <CONTAINER ID>
However I can't determine if it's possible to change an existing container, that originally was not run with the --restart="always"
option, to convert it to always restart in future.
Currently the only way I can think to do this is to save the container as a new image and then run that image as a new container with the --restart="always"
option. Would this in fact be the correct way to do this?
EDIT: What I perhaps didn't make clear enough originally is that I am thinking about the situation where there have been changes in the container since it was originally run, which need to be persisted. So just running a new container from the original image would not be sufficient.