$ docker run --restart=no busybox /bin/sh -c 'date; exit 1'
Wed Sep 17 08:13:15 UTC 2014
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e3389974b4ef busybox:latest "/bin/sh -c 'date; e 5 seconds ago Exited (1) 4 seconds ago jolly_hoover
$ docker run --restart=on-failure busybox /bin/sh -c 'date; exit 1'
Wed Sep 17 08:15:38 UTC 2014
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4fd4e22ecb35 busybox:latest "/bin/sh -c 'date; e 4 seconds ago Restarting (1) 1 seconds ago trusting_wilson
$ docker log 4fd4e22ecb35
Wed Sep 17 08:15:38 UTC 2014
Wed Sep 17 08:15:39 UTC 2014
Wed Sep 17 08:15:39 UTC 2014
Wed Sep 17 08:15:41 UTC 2014
Wed Sep 17 08:15:42 UTC 2014
Wed Sep 17 08:15:46 UTC 2014
Wed Sep 17 08:15:53 UTC 2014
// resetMonitor resets the stateful fields on the containerMonitor based on the
// previous runs success or failure. Reguardless of success, if the container had
// an execution time of more than 10s then reset the timer back to the default
func (m *containerMonitor) resetMonitor(successful bool) {
executionTime := time.Now().Sub(m.lastStartTime).Seconds()
if executionTime > 10 {
m.timeIncrement = defaultTimeIncrement
} else {
// otherwise we need to increment the amount of time we wait before restarting
// the process. We will build up by multiplying the increment by 2
m.timeIncrement *= 2
}
// the container exited successfully so we need to reset the failure counter
if successful {
m.failureCount = 0
} else {
m.failureCount++
}
}
docker run --restart=on-failure:5 busybox /bin/sh -c 'date; exit 1'
Wed Sep 17 08:51:05 UTC 2014
$ docker ps -a ➜ ~/src/github.com/tcnksm/docker-1.2
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c5a86fc5e242 busybox:latest "/bin/sh -c 'date; e 2 seconds ago Restarting (1) Less than a second ago cocky_hawking
$ docker logs c5a86fc5e242
Wed Sep 17 08:51:05 UTC 2014
Wed Sep 17 08:51:06 UTC 2014
Wed Sep 17 08:51:07 UTC 2014
Wed Sep 17 08:51:08 UTC 2014
Wed Sep 17 08:51:10 UTC 2014
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c5a86fc5e242 busybox:latest "/bin/sh -c 'date; e 29 seconds ago Exited (1) 24 seconds ago cocky_hawking
exit 0だと再起動しない
$ docker run --restart=on-failure busybox /bin/sh -c 'date; exit 0'
Wed Sep 17 08:54:21 UTC 2014
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
17849c6ee53b busybox:latest "/bin/sh -c 'date; e 4 seconds ago Exited (0) 3 seconds ago grave_babbage
docker run --restart=always busybox /bin/sh -c 'date; exit 0'
Wed Sep 17 08:57:34 UTC 2014
docker run --restart=always busybox /bin/sh -c 'date; exit 1'
Wed Sep 17 08:57:37 UTC 2014
docker ps -a ➜ ~/src/github.com/tcnksm/docker-1.2
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
19df55aec365 busybox:latest "/bin/sh -c 'date; e 4 seconds ago Restarting (1) 1 seconds ago drunk_ritchie
a158cdffcaae busybox:latest "/bin/sh -c 'date; e 8 seconds ago Restarting (0) 3 seconds ago naughty_mclean