Container auto-start Docker provides a restart policy mechanism that can control the container to automatically start when the container exits or Docker is restarted. This Restart policy ensures that related containers are started in the correct order. Although this action can also be accomplished through process monitoring (such as systemd), Docker still recommends avoiding the use of process monitoring to "self-start" containers. There is a difference between Docker's Restart policy and the --live-restore startup flag of the dockerd command: the --live-restore flag ensures that the container continues to run when Docker is upgraded, but the network and user terminal input will be interrupted. So what exactly is a restart policy? Let's take a look at the actual situation. Using restart policy The restart policy is specified by the --restart flag when starting the container using docker run. This flag has multiple values to choose from, and different values have different behaviors, as listed in the following table:
For example: The following command starts a Redis container. When the Redis container is stopped or Docker is restarted, the Redis container will be restarted. $ docker run -dit --restart unless-stopped redis Restart policy details When using restart policies, you need to pay attention to the following details: (1) The restart policy takes effect only after the container is successfully started. "Successful start" here means that the container has been up for at least 10 seconds and has been supervised by Docker. This is to prevent containers that have not been successfully started from falling into an endless loop of restarting. (2) If you manually stop a container (what is the difference from explicitly stopped above), the restart policy set for the container will be ignored unless the Docker daemon is restarted or the container is manually restarted. This avoids another vicious cycle. (3) Restart policies can only be used for containers. For swarm services, restart policies have invalid configurations. Process Monitoring If the restart policies mentioned above cannot meet your needs, you can also use process monitoring management solutions, such as upstart, systemd or supervisor, etc. In this solution, the process monitoring service runs in the container. It can monitor whether a process is running and can start the process if it is not running. Docker is completely unaware of all this happening. Docker does not recommend this method for process monitoring. The reason is simple. This method is related to the system platform and even the Linux distribution. Original: https://docs.docker.com/engine/admin/start-containers-automatically/#use-a-process-manager Docker container automatically starts at boot When starting the container with docker run, use the --restart parameter to set: # docker run -m 512m --memory-swap 1G -it -p 58080:8080 --restart=alway --name bvrfis --volumes-from logdata mytomcat:4.0 /root/run.sh --restart specific parameter value details:
You can also specify the maximum number of times Docker will attempt to restart the container when using the on-failure strategy. By default, Docker will try to restart containers forever. # sudo docker run --restart=on-failure:10 redis The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Problems and solutions for MYSQL5.7.17 connection failure under MAC
>>: JS implements click drop effect
Today I want to summarize several very useful HTML...
Table of contents Million-level data processing s...
Today I looked at some things related to data bac...
Since this is my first post, if there are any mis...
Table of contents Interpolation Expressions metho...
Sometimes the page is very long and needs an arro...
Adding/removing classes to elements is a very com...
1. Installation version details Server: MariaDB S...
I designed and customized a navigation bar with a...
1. Packaging Vue project Enter the following name...
1. Requirements description Display the delete ic...
The concept of lock ①. Lock, in real life, is a t...
Today I saw a blog post about input events, and o...
First: 4 ways to introduce CSS There are four way...
Preface This article uses the new features of MyS...