Docker provides restart policies to control whether your containers start automatically when they exit, or when Docker restarts.
Note* If you use docker stop or docker kill, it is expected that Docker does not restart the container. In case of docker stop or docker kill, its restart policy is gong to be ignored until the Docker daemon restarts or the container is manually restarted.
Container restart policy:
Container restart policy controls the restart actions when Container exits. Following are the supported restart options:
- no – This is default. Containers do not get restarted when they exit.
- on-failure – Containers restart only when there is a failure exit code. Any exit code other than 0 is treated as failure.
- unless-stopped – Containers restart as long as it was not manually stopped by user.
- always – Always restart container irrespective of exit status.
The following example starts a "selenium/node-chrome" container and configures it to always restart unless it is explicitly stopped or Docker is restarted.
$ docker run -d --restart unless-stopped selenium/node-chrome
This command changes the restart policy for an already running container named "selenium/node-chrome".
$ docker update --restart unless-stopped selenium/node-chrome
And this command will ensure all currently running containers will be restarted unless stopped.
$ docker update --restart unless-stopped $(docker ps -q)
Following is the list of standard and Docker defined exit codes:
- 0: Success
- 125: Docker run itself fails
- 126: Contained command cannot be invoked
- 127: Contained command cannot be found
- 128 + n: Fatal error signal n:
- 130: (128+2) Container terminated by Control-C
- 137: (128+9) Container received a SIGKILL
- 143: (128+15) Container received a SIGTERM
- 255: Exit status out of range(-1)
Comments
Post a Comment