This article is a mirror article of machine translation, please click here to jump to the original article.

View: 10111|Reply: 2

Docker looks at container restart settings and bulk stop containers

[Copy link]
Posted on 10/29/2021 1:57:51 PM | | | |
The restart strategy for the Docker --restart container is as follows:

no, the default policy, does not restart the container when it exits
on-failure, the container will be restarted when the container exits abnormally (the exit state is not 0).
on-failure:3,在容器非正常退出时重启容器,最多重启3次
always, always restart the container when it exits
unless-stopped, always restarts the container when it exits, but does not take into account containers that have been stopped when the Docker daemon starts

Check out the container restart setup command:



Modify the container restart policy with the following command:


The bulk stop container command is as follows:

(End)





Previous:Spring overrides the default configuration inside the jar package
Next:Java ThreadLocal principles and multi-threaded reuse lead to data clutter
 Landlord| Posted on 11/7/2021 10:04:34 PM |
unless-stopped is basically the same as always, with only one scenario that is a bit special:

If the container is stopped normally, and then the machine is restarted or the docker service is restarted, in which case the container will not be restarted
 Landlord| Posted on 9/4/2024 10:22:38 PM |
The --restart flag for Docker containers is used to define the container's restart policy. The two options, --restart=unless-stopped and --restart=always, have some subtle but important differences:

--restart=always:

  • The container will always try to restart, no matter how it stopped.
  • If the container crashes, it automatically restarts.
  • If the Docker daemon is restarted, the container will also start automatically.
  • Even if the container is stopped manually (as in using the docker stop command), it will restart when the Docker daemon restarts.

--restart=unless-stopped:

  • The container automatically restarts when it crashes.
  • If the Docker daemon is restarted, the container will also start automatically.
  • Key difference: If a container is manually stopped (e.g., using the docker stop command), it will not start automatically when the Docker daemon restarts.


Summary of the main differences:

The always policy attempts to restart the container in all cases, including after a manual stop.
unless-stopped strategyRespect the decision to stop manually, which does not automatically restart the container after a manual stop.

Selection recommendations:

If you want the container to run all the time, no matter what happens, choose always.
If you want to be able to manually stop the container and keep it stopped, even after a Docker restart, select unless-stopped.
This choice is important for managing and maintaining containers, especially when certain services need to be temporarily stopped or maintained. unless-stopped is generally considered a more flexible option, as it allows administrators to manually control the state of the container when needed.

Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com