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/