提交 cacf540b 编写于 作者: S storypku 提交者: Liu Jiaming

Scripts: descriptive cleanup_resources.sh on host

上级 c6ee809f
......@@ -16,18 +16,34 @@
# limitations under the License.
###############################################################################
if [ ! -z ${DOCKER_IMG} ]; then
echo "This script is expected to be run on host instead of the container."
echo "Please exit."
if [ -f /.dockerenv ]; then
echo "Oops, this script is expected to run on host rather than from within container."
exit 1
fi
# Credit to https://gist.github.com/bastman/5b57ddb3c11942094f8d0a97d461b430
echo "Cleanup containers..."
docker rm $(docker ps -qa --no-trunc --filter "status=exited")
exited_containers="$(docker ps -qa --no-trunc --filter "status=exited")"
if [ -z "${exited_containers}" ]; then
echo "Congrats, no exited docker containers found."
else
echo "Exited containers found, cleanup ..."
docker rm ${exited_containers}
fi
dangling_images="$(docker images --filter "dangling=true" -q --no-trunc)"
if [ -z "${dangling_images}" ]; then
echo "Congrats, no dangling docker images found."
else
echo "Dangling images found, cleanup ..."
docker rmi ${dangling_images}
fi
echo "Cleanup images..."
docker rmi $(docker images --filter "dangling=true" -q --no-trunc)
dangling_volumes="$(docker volume ls -qf dangling=true)"
if [ -z "${dangling_volumes}" ]; then
echo "Congrats, no dangling docker volumes found."
else
echo "Dangling volumes found, cleanup ..."
docker volume rm ${dangling_volumes}
fi
echo "Cleanup volumes..."
docker volume rm $(docker volume ls -qf dangling=true)
echo "Docker cleaning up finished."
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册