Want Docker to restart container on reboot?
This is quite simple with the Docker restart policies or a Process Manager.
But the better choice is to use the restart policy. Because it specifies how a container restart on exit.
At Bobcares, we often get requests to restart Docker on reboot, as a part of our Docker Hosting Support.
Today, we will see how our Support Engineers enable restart policy for Docker.
Snapshot on Docker restart policy
The restart policy is part of the container metadata. When we create the container, the metadata gets created.
By using the --restart
flag we can specify the restart policy for a Docker. The default restart policies are
no
– This default policy means no automatic restart of the container.on-failure
– It restarts the container only if it exits with a non-zero exit status.always
– It always restarts the container without looking for the current status of the container.unless-stopped
– Restart the container always except stopped.
Now let us see how to restart the container on reboot.
How we configure docker containers to restart on reboot?
Our Experts often configure Docker containers to restart on reboot. And we always recommend using a restart policy. Alternatively, we can also use a Process Manager for the same purpose.
Restart policy to restart Docker on reboot
By default, the restart policy in Docker is no. For already created containers, our Support Engineers use docker update to start restart policy.
The command appears as,
Here 0576df221c0b is the container ID.
Similarly, for the newly created container, we use the command,
This will make Docker restart on reboot.
Using Process manager to restart Docker on reboot
In some cases, we use a Process Manager in Linux to automatically restart services that fail. Common Process Managers are systemd, supervisor, etc.
We can use this in the case of Docker also. We recommend this option only if any outside process depends on the docker container.
Now, we will see how our Support Engineers use a Process Manager to restart Docker.
For this, we configure the Process Manager to start the container using the default manual commands.
But we do not recommend to use both the restart policy along with the Process Manager. Similarly, it is not advisable to use the Process Manager inside a container.
[Need assistance in managing Docker? – We will help you.]
Conclusion
So far, we saw two ways for a Docker to restart the container on reboot. The recommended method is to use Docker restart policy. But we may also use the Process Manager in some cases. Today, we also saw how our Support Engineers do this for our customers.
0 Comments