Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ mariadb-data
drunk_goodall
```

If you would prefer to not garbage collect any containers at all then
you can do this by setting the environment variable below:

```
REMOVE_CONTAINERS=0 docker-gc
```

### Forcing deletion of images that have multiple tags

By default, docker will not remove an image if it is tagged in multiple
Expand Down
13 changes: 8 additions & 5 deletions docker-gc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ set -o errexit

GRACE_PERIOD_SECONDS=${GRACE_PERIOD_SECONDS:=3600}
STATE_DIR=${STATE_DIR:=/var/lib/docker-gc}
REMOVE_CONTAINERS=${REMOVE_CONTAINERS:=1}
FORCE_CONTAINER_REMOVAL=${FORCE_CONTAINER_REMOVAL:=0}
FORCE_IMAGE_REMOVAL=${FORCE_IMAGE_REMOVAL:=0}
DOCKER=${DOCKER:=docker}
Expand Down Expand Up @@ -252,11 +253,13 @@ if [[ $FORCE_CONTAINER_REMOVAL -gt 0 ]]; then
FORCE_CONTAINER_FLAG="-f"
fi
# Reap containers.
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
if [[ $REMOVE_CONTAINERS -gt 0 ]]; then
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
fi

# Use -f flag on docker rmi command; forces removal of images that have multiple tags
Expand Down