Skip to content

Instantly share code, notes, and snippets.

@maxwu
Last active August 20, 2019 12:06
Show Gist options
  • Select an option

  • Save maxwu/1364bce6fcaa711fb5a0a81b3cfc8e30 to your computer and use it in GitHub Desktop.

Select an option

Save maxwu/1364bce6fcaa711fb5a0a81b3cfc8e30 to your computer and use it in GitHub Desktop.
Remove obsoleted docker images
#删除虚悬镜像
docker image prune --force
#删除停止或一直处于已创建状态的实例
docker ps --filter "status=exited"|sed -n -e '2,$p'|awk '{print $1}'|xargs docker rm
docker ps --filter "status=created"|sed -n -e '2,$p'|awk '{print $1}'|xargs docker rm
#删除REPOSITORY是长uuid的镜像
docker images | sed -n -e '2,$p'|awk '{if($1 ~ /[0-9a-f]{32}/) print $1":"$2}'|xargs docker rmi
#删除TAG是长uuid的镜像
docker images | sed -n -e '2,$p'|awk '{if($2 ~ /[0-9a-f]{64}/) print $1":"$2}'|xargs docker rmi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment