How to auto-restart Docker containers after a host server crash
Docker containers can be used to host applications ranging from one-time testing to 24/7 web hosting instances. Depending on its purpose, the system setup can vary.
Every Docker machine runs a ‘docker’ daemon, which is required for the containers to function. But during instances such as server crash or reboot, this daemon may not get restarted.
Today we’ll see what is Docker restart policy and how to auto-restart Docker containers to ensure that there is no service downtime.
What is Docker restart policy?
To ensure that the Docker daemon gets restarted after a host machine restart, you can enable the docker service to start in machine boot.
But that’s not enough to guarantee your business uptime. Because, by default, the Docker containers will not restart when the docker daemon is restarted.
As a result, even if the host machine or the docker service restarts, the containers in it would be non-functional. This would cause downtime for the businesses hosted in them.
For services that require high uptime, such as website hosting, it is therefore important to auto-restart Docker containers after restarting the docker daemon.
This can be now set using the Docker restart policy. A restart policy controls whether the Docker daemon restarts a container after exit.
Using the restart policy, when the docker daemon restarts, the containers will be restarted too. The default policy is ‘no’, as we discussed.
Docker supports the following restart policies for its containers and can be set during container start:
Bobcares provides Outsourced Hosting Support and Outsourced Server Management for online businesses. Our services include Hosting Support Services, server support, help desk support, live chat support and phone support.