Windows
详细说明请参考docker筛选容器和镜像
powershell
# 遍历匹配的镜像,遍历条件为列出"fun-cache"的镜像
docker rmi $(docker images -a fun-cache* -q) -f
12
下面这些有些复杂,可作为某些复杂条件下的参考
powershell
# 遍历匹配的镜像,遍历条件为列出"fun-cache"的镜像
docker image ls -a | grep fun-cache | where {($_ -match " \w{12} ")} | select {$matches[0].trim()} | select -ExpandProperty *
# Or
docker image ls -a | grep fun-cache | select {[regex]::matches($_, " \w{12} ").value.trim()} | select -ExpandProperty *
# Or
docker image ls -a | grep fun-cache | select @{label="match";expression={$_ -match " \w{12} "}},@{label="id";expression={$matches[0].trim()}} | select -ExpandProperty id
# 删除
docker rmi $(docker image ls -a | grep fun-cache | where {($_ -match " \w{12} ")} | select {$matches[0].trim()} | select -ExpandProperty *)
# 强制删除
docker rmi $(docker image ls -a | grep fun-cache | where {($_ -match " \w{12} ")} | select {$matches[0].trim()} | select -ExpandProperty *) -f
12345678910
Linux
shell
# 查找并删除镜像(xxx代表查询条件)
docker rmi `docker images | grep xxx | awk '{print $3}'`
# 查找并删除容器(xxx代表查询条件)
docker rm `docker ps -a | grep xxx | awk '{print $1}'`
12345
评论 (0)