Docker container self-starter __docker

Source: Internet
Author: User
Tags docker run
Original: https://docs.docker.com/engine/admin/start-containers-automatically/#use-a-process-manager
container self-starterThe Docker provides a restart policy mechanism that allows the control container to start itself when the container exits or Docker reboots. This restart policy ensures that the containers are started in the correct order. Although this can be done through process monitoring, such as SYSTEMD, Docker still recommends avoiding the "start" container in the way that process monitoring is used.
The Docker restart policy differs from the--live-restore boot flag of the Dockerd command: The--live-restore flag can keep the container running while the Docker is upgraded, but the network and user terminal input will be interrupted.
Then what exactly is restart policy? Let's take a look at the actual situation.

using restart policyRestart policy is specified by the--RESTART flag when using the Docker run startup container, this flag has multiple value options, and different value has different behavior, as listed in the following table:
Flag Description
No Does not automatically restart the container. (default value)
On-failure Container with Error and exit (container exit State is not 0) reboot container
unless-stopped Reboot the container when the container has been cut or Docker stoped/restarted
Always Reboot the container when the container has been cut or Docker stoped/restarted

For example: The following command launches a Redis container, and the Redis container reboots when the Redis container is stopped or Docker is restarted.
$ docker run-dit--restart unless-stopped Redis
Restart policy detailsThe following details need to be noted when using restart policies:
(1) The container can only take effect after the successful start-up of restart policy. The "successful launch" here means that the container is up to 10 seconds and is already under docker supervision. This is to avoid the failure of successful start-up of the container into a restart dead loop.
(2) If the manual (manually) stop (which is different from the previous explicitly stopped) is a container, the restart policy of the container setting will be ignored unless the Docker daemon reboot or the container is manually restarted. This is to avoid another kind of dead loop.
(3) Restart policies can only be used for containers, and for swarm services its restart policies has a configuration that is not passed.
Reference: Flags related to service restart

Process MonitoringIf the above mentioned restart policies not meet the requirements, you can also use process monitoring management solutions, such as UPSTART,SYSTEMD or supervisor, and so on.
In this scenario, the process monitoring service runs in the container. It can monitor whether a process is running and can start the process when it is not running. And all that happened was Docker unconscious.
Docker does not recommend this approach for process monitoring, for the simple reason that this approach is related to the system platform and even the Linux distribution.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.