From d0c0ffc19c25f8003e05ba85a5d43e33643fb731 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 6 Sep 2015 19:23:15 -0400 Subject: [PATCH] Do not remove any containers that have the label `dokku`. Closes #1220 This can be used to mark data containers as non-removable by the cleanup function --- plugins/common/functions | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/common/functions b/plugins/common/functions index 2d10c708d..12c6dc05b 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -322,9 +322,13 @@ release_and_deploy() { } docker_cleanup() { - # delete all non-running container + # delete all non-running containers + # if a container has the label `dokku`, + # then that container is not deleted. + # This can be used to mark data containers + # as non-removable by the cleanup function # shellcheck disable=SC2046 - docker rm $(docker ps -a -f 'status=exited' -q) &> /dev/null || true + docker rm $(comm <(docker ps -aq -f 'status=exited' | sort) <(docker ps -aq -f 'status=exited' -f 'label=dokku' | sort) -3) &> /dev/null || true # delete unused images # shellcheck disable=SC2046 docker rmi $(docker images -f 'dangling=true' -q) &> /dev/null &