1、说明
对于docker
镜像,尤其是开发应用构建的镜像,如果需要重新build镜像,而不改变原有版本号,则需要将原有dokcer
镜像删除。
删除命令很简单:docke rmi 镜像id
。
但有些场景直接删除会报如下错误。
$ docker rmi 42e04 Error response from daemon: conflict: unable to delete 42e04f0f9df2 (must be forced) - image is being used by stopped container 6503618ff193
例如以下场景会报错:
- 镜像运行的容器还在运行
- 镜像生产的容器还存在(未运行)。
2、删除方式
(1)查看运行的容器,只能查看正在运行的容易
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
(2)如果存在运行容器,则停止运行容器,使用: docker stop 容器id
。
(3)如果没有,则使用docker ps -a
方式查看未运行的容器。
$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6503618ff193 goon-dance-admin:1.0 "java -jar goon-danc…" 12 minutes ago Exited (1) 12 minutes ago goon-admin c5996e7a5ecc redis:alpine3.17 "docker-entrypoint.s…" 42 hours ago Exited (255) 18 hours ago 0.0.0.0:6389->6379/tcp redis-6389 d115623fada2 mysql/mysql-server:5.7.22 "/entrypoint.sh --ch…" 7 months ago Exited (255) 7 weeks ago 0.0.0.0:3306->3306/tcp, 33060/tcp mysql01 bf18c2fb05cb alpine/git "git clone https://g…" 7 months ago Exited (128) 7 months ago repo
(4)删除容器:docker rm 容器id
$ docker rm 6503618ff193 6503618ff193
(5)查看要删除的镜像id:docker ps
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE goon-dance-admin 1.0 42e04f0f9df2 15 minutes ago 643MB redis alpine3.17 1339d05b97a4 3 weeks ago 30.4MB alpine/git latest f404a400c0ad 8 months ago 39.5MB mysql/mysql-server 5.7.22 3cc9613ef3ba 4 years ago 244MB
(6)删除镜像:docker rmi 镜像id
$ docker rmi 42e04f Untagged: goon-dance-admin:1.0 Deleted: sha256:42e04f0f9df2d13bb23af6cfef9d60234ad5d3a1f8f6a5a76bcef4812736af87
以上就是docker删除镜像的实现方式详解的详细内容,更多关于docker删除镜像的资料请关注本站其它相关文章!