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
上一篇:【Process】方法中的相关异常汇总


下一篇:测试pyspark时,解决Java gateway process exited的问题