docker删除容器 镜像

docker删除容器 镜像
查看镜像
1.以下两种方式都可以
➜  ~ docker images
REPOSITORY             TAG       IMAGE ID       CREATED       SIZE
andyludocker/busybox   latest    491198851f0c   6 weeks ago   1.23MB
busybox                latest    491198851f0c   6 weeks ago   1.23MB
➜  ~
➜  ~
➜  ~ docker image list
REPOSITORY             TAG       IMAGE ID       CREATED       SIZE
andyludocker/busybox   latest    491198851f0c   6 weeks ago   1.23MB
busybox                latest    491198851f0c   6 weeks ago   1.23MB
➜  ~
查看容器
2.查询正在运行的容器
➜  ~ docker container list
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
➜  ~

➜  ~ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
➜  

3.查询之前在某些镜像上创建的容器
➜  ~ docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED       STATUS                     PORTS     NAMES
184f30a06a23   busybox   "sh"      2 weeks ago   Exited (0) 2 weeks ago             heuristic_kilby
10b5f61f2e2b   busybox   "sh"      2 weeks ago   Exited (130) 2 weeks ago             interesting_beaver
13b277f8c833   busybox   "sh"      2 weeks ago   Exited (130) 2 weeks ago             serene_agnesi
ed3e839fa79b   busybox   "sh"      5 weeks ago   Exited (0) 5 weeks ago               upbeat_hermann
8f450373c502   busybox   "sh"      5 weeks ago   Exited (127) 5 weeks ago             vigilant_jemison
删除镜像
前提:你可以使用docker rmi或者docker image rm命令删除镜像。我喜欢用后者 更清晰点

➜  ~ docker images
REPOSITORY             TAG       IMAGE ID       CREATED       SIZE
andyludocker/busybox   latest    491198851f0c   6 weeks ago   1.23MB
busybox                latest    491198851f0c   6 weeks ago   1.23MB
➜  ~
➜  ~
➜  ~


3.1.因为andyludocker/busybox是基于busybox创建的镜像 所以会报下面的重复删除错 
➜  ~ docker image rm 491198851f0c
Error response from daemon: conflict: unable to delete 491198851f0c (must be forced) - image is referenced in multiple repositories

3.2.不通过镜像id删除 
~ docker image rm busybox
Untagged: busybox:latest
Untagged: busybox@sha256:c6b45a95f932202dbb27c31333c4789f45184a744060f6e569cc9d2bf1b9ad6f

3.3.之后再删除andyludocker/busybox 报有容器使用该镜像
docker image rm andyludocker/busybox
Error response from daemon: conflict: unable to remove repository reference "andyludocker/busybox" (must force) - container ed3e839fa79b is using its referenced image 491198851f0c

3.4.直接强制删除
➜  ~ docker image rm -f 491198851f0c
Untagged: andyludocker/busybox:latest
Untagged: andyludocker/busybox@sha256:74e4a68dfba6f40b01787a3876cc1be0fb1d9025c3567cf8367c659f2187234f
Deleted: sha256:491198851f0ccdd0882cb9323f3856043d4e4c65b773e8eac3e0f6bc979a2ae7

3.5.发现镜像强制删除后 还存在脏数据
➜  ~ docker ps -a
CONTAINER ID   IMAGE          COMMAND   CREATED       STATUS                     PORTS     NAMES
184f30a06a23   491198851f0c   "sh"      2 weeks ago   Exited (0) 2 weeks ago               heuristic_kilby
10b5f61f2e2b   491198851f0c   "sh"      2 weeks ago   Exited (130) 2 weeks ago             interesting_beaver
13b277f8c833   491198851f0c   "sh"      2 weeks ago   Exited (130) 2 weeks ago             serene_agnesi
ed3e839fa79b   491198851f0c   "sh"      5 weeks ago   Exited (0) 5 weeks ago               upbeat_hermann
8f450373c502   491198851f0c   "sh"      5 weeks ago   Exited (127) 5 weeks ago             vigilant_jemison

3.6.可以通过容器id删除容器
➜  ~ docker container rm 184f30a06a23
184f30a06a23
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值