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

Exclude service images #171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions docker-gc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ SYSLOG_LEVEL=${SYSLOG_LEVEL:=info}
SYSLOG_TAG=${SYSLOG_TAG:=docker-gc}
DRY_RUN=${DRY_RUN:=0}
EXCLUDE_DEAD=${EXCLUDE_DEAD:=0}
EXCLUDE_SERVICE_IMAGE=${EXCLUDE_SERVICE_IMAGE:=0}

for pid in $(pidof -s docker-gc); do
if [[ $pid != $$ ]]; then
Expand Down Expand Up @@ -115,6 +116,16 @@ function compute_exclude_ids() {
# or imageid". Also delete blank lines or lines that only contain
# whitespace
sed 's/^\(.*\)$/ \1 /' $EXCLUDE_FROM_GC | sed '/^ *$/d' > $PROCESSED_EXCLUDES

# Keeping images used by a docker service on other node could be better,
# because those images are likely to be needed when swarm reschedule
# the service.
if [[ $EXCLUDE_SERVICE_IMAGE -gt 0 ]]; then
$DOCKER service ls \
| tail -n+2 \
| sed 's/^\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\).*/ \5 /' >> $PROCESSED_EXCLUDES
fi

# The following looks a bit of a mess, but here's what it does:
# 1. Get images
# 2. Skip header line
Expand Down