Merge pull request #1444 from progrium/docker-cleanup

Docker cleanup
This commit is contained in:
Jose Diaz-Gonzalez
2015-09-06 20:13:32 -04:00
2 changed files with 16 additions and 8 deletions

9
dokku
View File

@@ -53,7 +53,7 @@ case "$1" in
receive)
APP="$2"; IMAGE=$(get_app_image_name $APP); IMAGE_SOURCE_TYPE="$3"; TMP_WORK_DIR="$4"
dokku_log_info1 "Cleaning up..."
dokku cleanup
docker_cleanup
dokku_log_info1 "Building $APP from $IMAGE_SOURCE_TYPE..."
dokku build "$APP" "$IMAGE_SOURCE_TYPE" "$TMP_WORK_DIR"
release_and_deploy "$APP"
@@ -192,12 +192,7 @@ case "$1" in
;;
cleanup)
# delete all non-running container
# shellcheck disable=SC2046
docker rm $(docker ps -a -f 'status=exited' -q) &> /dev/null || true
# delete unused images
# shellcheck disable=SC2046
docker rmi $(docker images -f 'dangling=true' -q) &> /dev/null &
docker_cleanup
;;
plugins)

View File

@@ -82,7 +82,7 @@ dokku_log_verbose() {
}
dokku_log_warn() {
echo " ! $@"
echo " ! $@"
}
dokku_log_fail() {
@@ -320,3 +320,16 @@ release_and_deploy() {
echo
fi
}
docker_cleanup() {
# 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 $(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 &
}