docker批量删除容器、镜像
1、删除所有容器
docker rm `docker ps -a -q`
2、删除所有镜像
docker rmi `docker images -q`
3、按条件删除镜像
没有打标签
docker rmi `docker images -q | awk '/^<none>/ { print $3 }'`
镜像名包含关键字
docker rmi --force `docker images | grep doss-api | awk '{print $3}'` //其中doss-api为关键字
看来学会文本处理三剑客是必不可少的啊
在处理docker镜像的时候,强迫症,因为谷歌的镜像库访问不了,还要重新改tag,一个一个改?太麻烦,看
[root@master ~]# docker rmi `docker images |grep mirr|awk '{print $1":"$2}'`
Untagged: mirrorgooglecontainers/kube-proxy-amd64:v1.15.3
Untagged: mirrorgooglecontainers/kube-proxy-amd64@sha256:9f6befa52bcee298f4d363957d44803c13516a47d2b05cc71095a581d5af7e27
Untagged: mirrorgooglecontainers/kube-apiserver-amd64:v1.15.3
Untagged: mirrorgooglecontainers/kube-apiserver-amd64@sha256:12746ced388109e683af1c29c1c3657e0a1538030f40c0e17292f024af2bf765
Untagged: mirrorgooglecontainers/kube-controller-manager-amd64:v1.15.3
Untagged: mirrorgooglecontainers/kube-controller-manager-amd64@sha256:bfaa79ec3e1383ae29c6a577d85a94d88fecbf46d047453aa805e5958f2838ca
Untagged: mirrorgooglecontainers/kube-scheduler-amd64:v1.15.3
Untagged: mirrorgooglecontainers/kube-scheduler-amd64@sha256:37067863624b6d0f59341a8f58c419edfee15fb46dff0dfa61ab74c55cc1676b
Untagged: mirrorgooglecontainers/etcd-amd64:3.3.10
Untagged: mirrorgooglecontainers/etcd-amd64@sha256:8a82adeb3d0770bfd37dd56765c64d082b6e7c6ad6a6c1fd961dc6e719ea4183
[root@master ~]#
[root@master ~]#
[root@master ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
k8s.gcr.io/kube-proxy-amd64 v1.15.3 232b5c793146 4 weeks ago 82.4MB
k8s.gcr.io/kube-apiserver-amd64 v1.15.3 5eb2d3fc7a44 4 weeks ago 207MB
k8s.gcr.io/kube-controller-manager-amd64 v1.15.3 e77c31de5547 4 weeks ago 159MB
k8s.gcr.io/kube-scheduler-amd64 v1.15.3 703f9c69a5d5 4 weeks ago 81.1MB
coredns/coredns 1.3.1 eb516548c180 8 months ago 40.3MB
hello-world latest fce289e99eb9 8 months ago 1.84kB
k8s.gcr.io/etcd-amd64 3.3.10 2c4adeb21b4f 9 months ago 258MB
k8s.gcr.io/coredns 1.2.6 f59dcacceff4 10 months ago 40MB
k8s.gcr.io/pause 3.1 da86e6ba6ca1 21 months ago 742kB
[root@master ~]#
是不是很强
[root@master ~]# docker images |awk '{print $1":"$2}'
REPOSITORY:TAG
k8s.gcr.io/kube-proxy:v1.15.3
k8s.gcr.io/kube-apiserver:v1.15.3
k8s.gcr.io/kube-scheduler:v1.15.3
k8s.gcr.io/kube-controller-manager:v1.15.3
k8s.gcr.io/coredns:1.3.1
hello-world:latest
k8s.gcr.io/etcd:3.3.10
registry.cn-shanghai.aliyuncs.com/gcr-k8s/flannel:v0.10.0-amd64
k8s.gcr.io/pause:3.1