I see that Docker has added something called restarting policies to handle restart of containers in case of, for instance, reboot.
While this is very useful, I see that the restart policy command just work with docker run
and not docker start
. So my question is:
Is there any way to add restarting policies to a container that was already created in the past?
In recent versions of docker (as of 1.11) you have an update
command:
docker update --restart=always <container>
There're two approaches to modify RestartPolicy:
- Find out the container ID, stop the whole docker service, modify /var/lib/docker/containers/CONTAINER_ID/hostconfig.json, set RestartPolicy -> Name to "always", and start docker service.
docker commit
your container as a new image, stop & rm the current container, and start a new container with the image.
No. And more generally, you can't edit a container once it is created (exposed port, hostname, network settings) via Docker. You would need to recreate it with docker run
.
It is usually good practice to have your container stateless, so it should not cause any issue. Take a look at volumes (-v
) to help you achieve this.