Home  >  Article  >  Operation and Maintenance  >  Will docker automatically restart?

Will docker automatically restart?

藏色散人
藏色散人Original
2021-12-30 11:39:495235browse

Docker will automatically restart. The way to achieve this is to add the parameter "--restart=always" when starting the container to achieve automatic restart.

Will docker automatically 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:

Will docker automatically restart?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn