Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
store the list of containers/images kept and removed by docker-gc
Browse files Browse the repository at this point in the history
copy all files in one command
  • Loading branch information
andrewsykim committed Apr 4, 2016
1 parent fa99444 commit c6215c9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions docker-gc
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@
# containers were removed. To enable logging to syslog, set LOG_TO_SYSLOG=1.
# When disabled, this script will instead log to standard out. When syslog is
# enabled, the syslog facility and logger can be configured with
# $SYSLOG_FACILITY and $SYSLOG_LEVEL respectively.
# $SYSLOG_FACILITY and $SYSLOG_LEVEL respectively.

set -o nounset
set -o errexit

GRACE_PERIOD_SECONDS=${GRACE_PERIOD_SECONDS:=3600}
STATE_DIR=${STATE_DIR:=/var/lib/docker-gc}
LOG_HISTORY=${LOG_HISTORY:=0}
FORCE_CONTAINER_REMOVAL=${FORCE_CONTAINER_REMOVAL:=0}
FORCE_IMAGE_REMOVAL=${FORCE_IMAGE_REMOVAL:=0}
DOCKER=${DOCKER:=docker}
Expand Down Expand Up @@ -75,7 +76,7 @@ fi
EXCLUDE_CONTAINERS_FROM_GC=${EXCLUDE_CONTAINERS_FROM_GC:=/etc/docker-gc-exclude-containers}
if [ ! -f "$EXCLUDE_CONTAINERS_FROM_GC" ]
then
EXCLUDE_CONTAINERS_FROM_GC=/dev/null
EXCLUDE_CONTAINERS_FROM_GC=/dev/null
fi

EXCLUDE_IDS_FILE="exclude_ids"
Expand Down Expand Up @@ -143,7 +144,7 @@ function compute_exclude_container_ids() {
return
fi
# Find all docker images
# Filter out with matching names
# Filter out with matching names
# and put them to $EXCLUDE_CONTAINER_IDS_FILE
$DOCKER ps -a \
| grep -E "$PROCESSED_EXCLUDES" \
Expand Down Expand Up @@ -272,3 +273,10 @@ else
image_log "Removing image" images.reap
xargs -n 1 $DOCKER rmi $FORCE_IMAGE_FLAG < images.reap &>/dev/null || true
fi

if [[ $LOG_HISTORY -gt 0 ]]; then
timestamp=$(date +"%H-%M-%S-%Y-%m-%d")
log "Saving docker gc history under $STATE_DIR/history/$timestamp"
mkdir -p $STATE_DIR/history/$timestamp
cp $STATE_DIR/{images.reap,images.used,container.reap,container.keep} $STATE_DIR/history/$timestamp
fi

0 comments on commit c6215c9

Please sign in to comment.