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

Commit

Permalink
Add DRY_RUN option
Browse files Browse the repository at this point in the history
fix wrong logger, wrong message and wrong image list file
  • Loading branch information
zerthimon committed Mar 4, 2016
1 parent bfad050 commit a3b2d2a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ GRACE_PERIOD_SECONDS=86400 docker-gc

This setting also prevents the removal of images that have been created less than `GRACE_PERIOD_SECONDS` seconds ago.

### Dry run
By default, docker-gc will proceed with deletion of containers and images. To test your command-line options set the `DRY_RUN` variable to override this default.

```
DRY_RUN=1 docker-gc
```


## Running as a Docker Image

Expand Down
17 changes: 13 additions & 4 deletions docker-gc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ LOG_TO_SYSLOG=${LOG_TO_SYSLOG:=0}
SYSLOG_FACILITY=${SYSLOG_FACILITY:=user}
SYSLOG_LEVEL=${SYSLOG_LEVEL:=info}
SYSLOG_TAG=${SYSLOG_TAG:=docker-gc}
DRY_RUN=${DRY_RUN:=0}

for pid in $(pidof -s docker-gc); do
if [[ $pid != $$ ]]; then
Expand Down Expand Up @@ -251,8 +252,12 @@ if [[ $FORCE_CONTAINER_REMOVAL -gt 0 ]]; then
FORCE_CONTAINER_FLAG="-f"
fi
# Reap containers.
container_log "Container removed" containers.reap
xargs -n 1 $DOCKER rm $FORCE_CONTAINER_FLAG --volumes=true < containers.reap &>/dev/null || true
if [[ $DRY_RUN -gt 0 ]]; then
container_log "The following container would have been removed" containers.reap
else
container_log "Removing containers" containers.reap
xargs -n 1 $DOCKER rm $FORCE_CONTAINER_FLAG --volumes=true < containers.reap &>/dev/null || true
fi

# Use -f flag on docker rmi command; forces removal of images that have multiple tags
FORCE_IMAGE_FLAG=""
Expand All @@ -261,5 +266,9 @@ if [[ $FORCE_IMAGE_REMOVAL -gt 0 ]]; then
fi

# Reap images.
image_log "Removing image" images.reap
xargs -n 1 $DOCKER rmi $FORCE_IMAGE_FLAG < images.reap &>/dev/null || true
if [[ $DRY_RUN -gt 0 ]]; then
image_log "The following image would have been removed" images.reap
else
image_log "Removing image" images.reap
xargs -n 1 $DOCKER rmi $FORCE_IMAGE_FLAG < images.reap &>/dev/null || true
fi

0 comments on commit a3b2d2a

Please sign in to comment.