docker删除报错 Error response from daemon: conflict: unable to delete (cannot be forced)

强制删除

docker删除镜像报错,报错信息如下后输出如下:

$ docker rmi ed603a4c67bb
Error response from daemon: conflict: unable to delete ed603a4c67bb (must be forced)
 - image is referenced in multiple repositories
docker images后输出如下:
```bash
REPOSITORY                       TAG                 IMAGE ID            CREATED             SIZE
springboot                       latest              ed603a4c67bb        9 minutes ago       265MB
springboot-jdk8                  2.0.3               ed603a4c67bb        9 minutes ago       265MB
redis                            latest              621ceef7494a        4 days ago          104MB

解决方案:

  1. docker rmi 时指定名称
$ docker rmi springboot:latest
  1. 强制删除 增加 -f 参数
$ docker rmi -f ed603a4c67bb
删除成功如下信息:
Untagged: springboot-jdk8:2.0.3
Untagged: springboot:latest
Deleted: sha256:ed603a4c67bb6ce3c540fc5173107e80850bf5428972d3297e14b49f6db6cc0f
Deleted: sha256:d33d8db811d2c9a4cff9d9da28ab31b98bc1ed406dd55d3b32cbb951c8ac8161
Deleted: sha256:8d25b50acae7f34b4ef40bc61297928b670a6c76cada996a737f922446f10c6b
Deleted: sha256:994e67acf7a19ba85ce6ecfa2d3852e76314b69561f9bcac6754fe32829ee092
Deleted: sha256:13c71e09d596eabcf37929bd676d273d471036b93ef5e55430d98d05cf1eb1c1
Deleted: sha256:7b179569fcced5870f0d04e642219affaad3eea661bdd1fbbaa4e8e0449ee745
Deleted: sha256:c5f4ee466d14804a5e4f9ee11741f890aa4488dcd6196138bf29c2a7b254a750
Deleted: sha256:e64ade6f68a833a04a5c1651eedb982c864d8f983e592e2d3dea5a37efeef627
运行时的删除
docker rmi ed603a4c67bb
Error response from daemon: conflict: unable to delete ed603a4c67bb (cannot be forced) 
- image is being used by running container ba0db34470ce

可以看出镜像正在运行中,检查是否有容器正在使用该镜像;检查得出该容器正在运行,先停止该容器进行删除,这种情况经常会发生在通过docker-compose构建镜像的时候,多次构建等;先通过docker-compose down 停止服务;后再次执行删除;

更多删除命令
  • 删除所有未被 tag 标记和未被容器使用的镜像:
$ docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
  • 删除所有未被容器使用的镜像:
$ docker image prune -a
  • 删除所有停止运行的容器:
$ docker container prune
  • 删除所有未被挂载的卷:
$ docker volume prune
  • 删除所有网络:
$ docker network prune
  • 删除 docker 所有资源:
$ docker system prune

你可能感兴趣的:(容器技术,docker)