Skip to content

Commit

Permalink
Merge pull request spotify#3 from rccrdpccl/add-only-driver-volume-de…
Browse files Browse the repository at this point in the history
…lete

add VOLUME_DELETE_ONLY_DRIVER
  • Loading branch information
rccrdpccl committed Nov 23, 2016
2 parents 4496f30 + 98ed22b commit 6b7257e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,10 @@ $ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /etc:/etc spot
The `/etc` directory is also mapped so that it can read any exclude files
that you've created.

If you want to remove volumes, you can do it so by passing REMOVE_VOLUMES env var set to 1.
If you want to remove volumes, you can do so by passing REMOVE_VOLUMES env var set to 1.

```sh
$ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /etc:/etc -e REMOVE_VOLUMES=1 spotify/docker-gc
```

If you want to remove volumes only for a specified driver, you can do it by passing VOLUME_DELETE_ONLY_DRIVER env var set to the driver name.
7 changes: 6 additions & 1 deletion docker-gc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ DRY_RUN=${DRY_RUN:=0}
EXCLUDE_DEAD=${EXCLUDE_DEAD:=0}
REMOVE_VOLUMES=${REMOVE_VOLUMES:=0}
EXCLUDE_VOLUMES_IDS_FILE=${EXCLUDE_VOLUMES_IDS_FILE:=/etc/docker-gc-exclude-volumes}
VOLUME_DELETE_ONLY_DRIVER=${VOLUME_DELETE_ONLY_DRIVER:=locale}

for pid in $(pidof -s docker-gc); do
if [[ $pid != $$ ]]; then
Expand Down Expand Up @@ -323,7 +324,11 @@ if [[ $REMOVE_VOLUMES -gt 0 ]]; then
log "$MESSAGE"
fi
else
$DOCKER volume ls --filter "dangling=true" -q | grep -v -f $EXCLUDE_VOLUMES_IDS_FILE > volumes.reap
if [[ -z "$VOLUME_DELETE_ONLY_DRIVER" ]]; then
$DOCKER volume ls --filter "dangling=true" -q | grep -v -f $EXCLUDE_VOLUMES_IDS_FILE > volumes.reap
else
$DOCKER volume ls --filter "dangling=true" --filter "driver=$VOLUME_DELETE_ONLY_DRIVER" -q | grep -v -f $EXCLUDE_VOLUMES_IDS_FILE > volumes.reap
fi

if [[ $DRY_RUN -gt 0 ]]; then
volumes_log "The following volume would have been removed" volumes.reap
Expand Down

0 comments on commit 6b7257e

Please sign in to comment.