这里是普通文章模块栏目内容页
Docker删除某个容器时失败解决方案

删除某个容器时,报错

docker rm 容器id 
image is being used by stopped container e11efb30362a
该报错的原因是要删除的该镜像,被某个容器所引用

解决方案

执行命令

docker ps -a

该命令的含义是查看所有的容器,包括未运行的容器.通过执行该命令,可以看到,有一个容器引用了该镜像

root@ubuntu:~# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                        PORTS               NAMES
4a36731987fd        tomcat              "catalina.sh run"   20 minutes ago      Exited (143) 16 minutes ago                       vibrant_bouman
e11efb30362a        myshop              "catalina.sh run"   6 months ago        Exited (130) 6 months ago                         blissful_khayyam

执行命令docker rm e11efb30362a 删除该容器.

docker rm e11efb30362a

列出镜像、再删除镜像

docker images
root@ubuntu:~# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
myshop              latest              c190f3e2478b        6 months ago        508MB
tomcat              latest              8973f493aa0a        6 months ago        508MB

删除镜像(rmi 批量删除)

docker rmi c190f3e2478b