From df6ff40651d4521105f687f32c4b04f78e5a861f Mon Sep 17 00:00:00 2001 From: Ardjan Dommisse Date: Mon, 4 Sep 2017 12:10:05 +0200 Subject: [PATCH] Containers in the Created state now respect the GRACE_PERIOD_SECONDS --- docker-gc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docker-gc b/docker-gc index 28a0183..3227393 100755 --- a/docker-gc +++ b/docker-gc @@ -222,8 +222,10 @@ container_log "Container not running" containers.exited > containers.reap.tmp cat containers.exited | while read line do - EXITED=$(${DOCKER} inspect -f "{{json .State.FinishedAt}}" ${line}) - ELAPSED=$(elapsed_time $EXITED) + # The .Created timestamp only exists for ontainers in the Created State. + # The .State.FinishedAt is invalid for containers in the Created State. + IFS=' ' read FINISHED_AT CREATED <<< $(${DOCKER} inspect -f "{{json .State.FinishedAt}} {{json .Created}}" ${line}) + ELAPSED=$(elapsed_time ${CREATED:-$FINISHED_AT}) if [[ $ELAPSED -gt $GRACE_PERIOD_SECONDS ]]; then echo $line >> containers.reap.tmp fi