# Use `docker-cleanup --dry-run` to see what would be deleted. function docker-cleanup { EXITED=$(docker ps -q -f status=exited) DANGLING=$(docker images -q -f "dangling=true")
if [ "$1" == "--dry-run" ]; then echo"==> Would stop containers:" echo$EXITED echo"==> And images:" echo$DANGLING else if [ -n "$EXITED" ]; then docker rm$EXITED else echo"No containers to remove." fi if [ -n "$DANGLING" ]; then docker rmi $DANGLING else echo"No images to remove." fi fi }
移除所有容器和镜像的基本步骤脚本
1 2 3 4 5 6 7 8 9 10 11 12
#!/bin/bash # 1. List all the containers docker ps -aq