Docker will automatically restart. The way to achieve this is to add the parameter "--restart=always" when starting the container to achieve automatic restart.
The operating environment of this article: ubuntu 18.04 system, Docker version 20.10.11, Dell G3 computer.
Will docker automatically restart?
docker will automatically restart.
How to make Docker containers automatically restart:
Problem
System restart, Docker restart, etc. will cause the running container to stop running, and you have to Start the container again, but this is really troublesome. In fact, Docker provides an automatic restart mechanism.
Solution
When starting the container, just add the parameter --restart=always to achieve automatic restart, as follows:
$ docker run --restart=always
The restart strategy provided by Docker is not only always, but also as follows:
unless-stopped usage is as follows:
$ docker run -d --restart unless-stopped redis
For containers that are already running
For containers that are already running, and the --restart parameter is not added when starting, you can increase it through the update command:
$ docker update --restart=always xxx
For the number of on-failures
For the policy on -failure can increase the number of times to prevent unlimited restarts:
$ sudo docker run --restart=on-failure:10 redis
Recommended learning: "docker video tutorial"
The above is the detailed content of Will docker automatically restart?. For more information, please follow other related articles on the PHP Chinese website!