Docker container restart strategy and--restart options for Docker run

Source: Internet
Author: User
Tags docker ps docker run

1. Docker Container Restart policy

The restart policy for Docker containers is a start-up strategy for production environments that can be ignored during the development process.

Docker container restarts are done by the Docker daemon and are therefore closely related to the daemon process.

The Docker container restart policy is as follows:

No, the default policy, when the container exits without restarting the container on-failure, when the container exits abnormally (exit status is not 0), will restart the container on-failure:3, restart the container when the container exits abnormally, restart the containers at most 3 times, always restart the container when the container exits Unless-stopped, always restarts the container when the container exits, but does not consider containers that have stopped when the Docker daemon is started


2. Exit status code for Docker containers

The exit status code for Docker run is as follows:
0, the normal exit is not 0, indicating an abnormal exit (exit status code with the Chroot standard) 125,docker daemon itself error 126, after the container starts, the default command to execute cannot call 127, after the container starts, the default command to execute does not exist other command status code, When the container starts to execute the command normally, the return status code of the command is returned as the exit status code of the container when the command exits.

3. The--restart option for Docker run allows you to set the container restart policy by--restart option to determine whether the Docker daemon restarts the container that just exited when the container exits.

The--restart option is typically used only for containers in detached mode.

The--restart option cannot be used in conjunction with the--RM option. Obviously, the--restart option applies to containers in detached mode, while the--RM option applies to containers in foreground mode.

When Docker PS is viewing a container, it may have a status of up or restarting two for containers that use the--restart option.

Example:
Docker run-d--restart=always bba-208
Docker run-d--restart=on-failure:10 bba-208

Add:

To view the number of container restarts
Docker Inspect-f "{{. Restartcount}} "bba-208
To view the last start time of a container
Docker Inspect-f "{{. State.startedat}} "bba-208


Reference Links:

https://docs.docker.com/engine/reference/run/


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.