How to delete an image in Docker

How to delete an image in Docker

The command to delete images in docker is docker rmi, but sometimes executing this command cannot delete images

[yaxin@ubox ~]
$docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
eg_sshd latest ed9c93747fe1 45 hours ago 329.8 MB
CentOS65 latest e55a74a32125 2 days ago 360.6 MB
[yaxin@ubox ~]$docker rmi ed9c93747fe1
Untagged: ed9c93747fe16627be822ad3f7feeb8b4468200e5357877d3046aa83cc44c6af
[yaxin@ubox ~]$docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
<none> <none> ed9c93747fe1 45 hours ago 329.8 MB
CentOS65 latest e55a74a32125 2 days ago 360.6 MB

It can be seen that the image has not been deleted, but its tag has been deleted. Executing docker rmi IMAGE_ID again will only result in an error.

[yaxin@ubox ~]
$ docker rmi ed9c93747fe1
Error: image_delete: Conflict, ed9c93747fe1 wasn't deleted
2014/03/22 15:58:27 Error: failed to remove one or more images

Looking at the docker help, you will find two commands related to deletion: rm and rmi

rm Remove one or more containers
rmi Remove one or more images

There are two different words here, images and container. Images are easy to understand. They have the same meaning as the virtual machine images we usually use, which are equivalent to templates, while containers are the states of images when they are running. Docker retains a status (container) for each image that has been run. You can use the docker ps command to view the running container. For the exited container, you can use docker ps -a to view it. If you exit a container and forget to save the data in it, you can use docker ps -a to find the corresponding running container, use the docker commit command to save it as an image and then run it.

Back to the previous question, since the image is referenced (used to run) by a container, if the referenced container is not destroyed (deleted), the image cannot be deleted.

So if you want to delete a runned image, you must first delete its container. Let’s continue with the previous example.

[yaxin@ubox ~]
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
117843ade696 ed9c93747fe1 /bin/sh -c /usr/sbin 46 hours ago Up 46 hours 0.0.0.0:49153->22/tcp test_sshd

It can be seen that the image ed9c93747fe1 is used by the container 117843ade696, so the container must be deleted first.

[yaxin@ubox ~]
$ docker rm 117843ade696
Error: container_delete: Impossible to remove a running container, please stop it first
2014/03/22 16:36:44 Error: failed to remove one or more containers

An error occurred because the container is running (run docker ps to view it), close it first

[yaxin@ubox ~]
$ docker stop 117843ade696
117843ade696
[yaxin@ubox ~]
$ docker rm 117843ade696
117843ade696
[yaxin@ubox ~]$docker rmi ed9c93747fe1
Deleted: ed9c93747fe16627be822ad3f7feeb8b4468200e5357877d3046aa83cc44c6af
Deleted: c8a0c19429daf73074040a14e527ad5734e70363c644f18c6815388b63eedc9b
Deleted: 95dba4c468f0e53e5f1e5d76b8581d6740aab9f59141f783f8e263ccd7cf2a8e
Deleted: c25dc743e40af6858c34375d450851bd606a70ace5d04e231a7fcc6d2ea23cc1
Deleted: 20562f5714a5ce764845119399ef75e652e23135cd5c54265ff8218b61ccbd33
Deleted: c8af1dc23af7a7aea0c25ba9b28bdee68caa8866f056e4f2aa2a5fa1bcb12693
Deleted: 38fdb2c5432e08ec6121f8dbb17e1fde17d5db4c1f149a9b702785dbf7b0f3be
Deleted: 79ca14274c80ac1df1333b89b2a41c0e0e3b91cd1b267b31bef852ceab3b2044
[yaxin@ubox ~]$docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
CentOS65 latest e55a74a32125 2 days ago 360.6 MB

It can be seen that the image has been deleted.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Talk about the issue of replacing docker (shim) with containerd in kubernetes1.20
  • How to keep running after exiting Docker container
  • Docker removes abnormal container operations
  • Goodbye Docker: How to Transform to Containerd in 5 Minutes
  • Docker dynamically exposes ports to containers
  • Delete the image operation of none in docker images
  • Implementation of local migration of docker images
  • Solve the problem of docker images disappearing
  • Docker image cannot be deleted Error: No such image: xxxxxx solution
  • Naming containers and images in Docker

<<:  React mouse multi-selection function configuration method

>>:  MySQL Installer Community 5.7.16 installation detailed tutorial

Recommend

Tutorial on installing mysql8 on linux centos7

1. RPM version installation Check if there are ot...

Detailed application of Vue dynamic form

Overview There are many form requirements in the ...

Summary of the most commonly used knowledge points about ES6 new features

Table of contents 1. Keywords 2. Deconstruction 3...

The role of nextTick in Vue and several simple usage scenarios

Purpose Understand the role of nextTick and sever...

MySQL 5.7.17 winx64 installation and configuration method graphic tutorial

Windows installation mysql-5.7.17-winx64.zip meth...

Detailed tutorial on installing Protobuf 3 on Ubuntu

When to install If you use the protoc command and...

How to install vim editor in Linux (Ubuntu 18.04)

You can go to the Ubuntu official website to down...

Setting up a proxy server using nginx

Nginx can use its reverse proxy function to imple...

javascript implements web version of pinball game

The web pinball game implemented using javeScript...

Specific operations of MYSQL scheduled clearing of backup data

1|0 Background Due to project requirements, each ...

Installation method of MySQL 5.7.18 decompressed version under Win7x64

Related reading: Solve the problem that the servi...

Detailed explanation of the use of Vue h function

Table of contents 1. Understanding 2. Use 1. h() ...