From 18a454786995728879c7481b746f28ef154b05f0 Mon Sep 17 00:00:00 2001 From: lmickh Date: Wed, 21 Sep 2016 09:44:17 -0500 Subject: [PATCH 1/2] gh-127 prevent from killing created containers --- docker-gc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docker-gc b/docker-gc index d0af59f..9496e5f 100755 --- a/docker-gc +++ b/docker-gc @@ -222,7 +222,10 @@ container_log "Container not running" containers.exited cat containers.exited | while read line do EXITED=$(${DOCKER} inspect -f "{{json .State.FinishedAt}}" ${line}) - ELAPSED=$(elapsed_time $EXITED) + CREATED=$(${DOCKER} inspect -f "{{json .Created}}" ${line}) + ELAPSED_EXITED=$(elapsed_time $EXITED) + ELAPSED_CREATED=$(elapsed_time $CREATED) + ELAPSED=$( (( $ELAPSED_EXITED >= $ELAPSED_CREATED )) && echo "$ELAPSED_EXITED" || echo "$ELAPSED_CREATED" ) if [[ $ELAPSED -gt $GRACE_PERIOD_SECONDS ]]; then echo $line >> containers.reap.tmp fi From 39b4ff7403e1afb3ef92563d5a0231c491279302 Mon Sep 17 00:00:00 2001 From: lmickh Date: Wed, 21 Sep 2016 10:03:51 -0500 Subject: [PATCH 2/2] Typo on comparision --- docker-gc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-gc b/docker-gc index 9496e5f..20c0e06 100755 --- a/docker-gc +++ b/docker-gc @@ -225,7 +225,7 @@ do CREATED=$(${DOCKER} inspect -f "{{json .Created}}" ${line}) ELAPSED_EXITED=$(elapsed_time $EXITED) ELAPSED_CREATED=$(elapsed_time $CREATED) - ELAPSED=$( (( $ELAPSED_EXITED >= $ELAPSED_CREATED )) && echo "$ELAPSED_EXITED" || echo "$ELAPSED_CREATED" ) + ELAPSED=$( (( $ELAPSED_EXITED <= $ELAPSED_CREATED )) && echo "$ELAPSED_EXITED" || echo "$ELAPSED_CREATED" ) if [[ $ELAPSED -gt $GRACE_PERIOD_SECONDS ]]; then echo $line >> containers.reap.tmp fi