From 8949f9561481696d487720ac779b8d0ae0309c24 Mon Sep 17 00:00:00 2001 From: Ronak Patel <36863182+rpatel-vt@users.noreply.github.com> Date: Mon, 13 Aug 2018 17:16:59 -0700 Subject: [PATCH 1/2] Update docker-gc --- docker-gc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docker-gc b/docker-gc index 25b2110..a0a940b 100755 --- a/docker-gc +++ b/docker-gc @@ -238,6 +238,12 @@ cat containers.exited | while read line do EXITED=$(${DOCKER} inspect -f "{{json .State.FinishedAt}}" ${line}) ELAPSED=$(elapsed_time $EXITED) + # If the container never started/finished and only was created + # we compare the created date. + if [ $ELAPSED = "0001-01-01T00:00:00Z" ] ; then + CREATEDAT=$(${DOCKER} inspect -f "{{json .Created}}" ${line}) + ELAPSED=$(elapsed_time $CREATEDAT) + fi if [[ $ELAPSED -gt $GRACE_PERIOD_SECONDS ]]; then echo $line >> containers.reap.tmp fi From b1f3dd24067fe28e2641946233630318e62dda08 Mon Sep 17 00:00:00 2001 From: Ronak Patel <36863182+rpatel-vt@users.noreply.github.com> Date: Mon, 13 Aug 2018 17:53:43 -0700 Subject: [PATCH 2/2] quote it and update var --- docker-gc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-gc b/docker-gc index a0a940b..f883bd8 100755 --- a/docker-gc +++ b/docker-gc @@ -240,10 +240,10 @@ do ELAPSED=$(elapsed_time $EXITED) # If the container never started/finished and only was created # we compare the created date. - if [ $ELAPSED = "0001-01-01T00:00:00Z" ] ; then + if [ $EXITED = '"0001-01-01T00:00:00Z"' ] ; then CREATEDAT=$(${DOCKER} inspect -f "{{json .Created}}" ${line}) ELAPSED=$(elapsed_time $CREATEDAT) - fi + fi if [[ $ELAPSED -gt $GRACE_PERIOD_SECONDS ]]; then echo $line >> containers.reap.tmp fi