docker delete image

Transferred from:


Because you try to use a new image, delete the original image. The error is as follows:

Error response from daemon: conflict: unable to delete 037c233c605c (must be forced) - image is being used by stopped container 65e94723f0ed

This means to delete the corresponding docker before deleting the image Image deletion failed because the image is referenced by the corresponding container.

[root@vm000949 redis]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
mia/redis                 v2                  a061cf8c12b8        48 minutes ago      210.7 MB
<none>                    <none>              037c233c605c        2 days ago          203.5 MB

I mainly want to delete these two imgae s and find them in the container according to the id of the image

[root@vm000949 redis]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                       PORTS               NAMES
1be364973e1d        a061cf8c12b8        "/bin/bash"              42 minutes ago      Exited (137) 5 minutes ago                       thirsty_einstein
65e94723f0ed        037c233c605c        "/bin/sh -c 'yum -y u"   2 days ago          Exited (1) 2 days ago                            gloomy_mestorf

Ok. Delete them

[root@vm000949 redis]# docker rm 65e94723f0ed
[root@vm000949 redis]# docker rm 1be364973e1d

Delete the image again. OK, it's successful.

[root@vm000949 redis]# docker rmi a061cf8c12b8
Untagged: mia/redis:v2
Deleted: sha256:a061cf8c12b8a23ea9fe85ebcfc32615f8e9a38dd95961b0dd80ceae658cdc5a
Deleted: sha256:f80464ae70055852f02c7763858dd97121c0e3d77430cb4df2dc70aec1c19678
Deleted: sha256:cdcbccf2d746d094040b8383868120d6d73327827b6ee83a8989baab9bf5fa42
[root@vm000949 redis]# docker rmi 037c233c605c
Deleted: sha256:037c233c605c5b4266ef6cc208d6c1a07b01fab77e848ec0bbb3bb01bdb3fda1
Deleted: sha256:7e07f5920a8cef8dbc5a5a663b14dc37d1112b259d93629aa8ded32f0ea0a6ae

You can also add - f to forcibly delete the image according to the prompt.
By the way, the docker command:
1. Docker RM < container ID or container name >
2. Docker stop < container ID or container name >

Extension: 1 How to delete all containers; 2. How to delete all container images, 3 When creating an image, many intermediate images will be generated. Are these images deleted together? none mirror?

1. First, solve the first point

docker rm $(docker ps -aq)

Here, the commands of docker ps include:
1) - a list all containers
2) - l list newly created containers
3) - n=2 lists the 2 recently created containers
4) - q list container ID S only
5) - s displays the container size
So docker ps -aq is equivalent to listing all container ID s and then docker rm them

However, it should be noted that if the container is running and cannot be deleted, it needs to be stopped first:

Docker stop $(docker ps -aq)

2. What about similar docker image s?
The image deletion syntax is:

docker rmi [OPTIONS] [IMAGEID]

The parameters of OPTIONS include: - f force deletion, - no prune: do not remove the process image generated by the image. The default is remove.

For example:

Docker rmi $(docker ps -aq)

The -aq display here is the ID of the image

3. if you want to delete the none image without a tag:

Docker rmi $(docker images -a|grep none|awk '{print $3}')

It can also be written as:

docker ps -a |grep none }awk '{print $1}'|xargs docker rmi

Pass in parameter xagrs
What happens to the image of none?
1) If the creation fails during the image creation process, an invalid none image will be generated
2) pull image. Mirror's vertical parent-child relationship
3) Use the dockerfile file to create an image and regenerate it. Assign a new image name to the latter. The previous image name is none

reference material:
[1]docker force batch deletion of image images of none
[2]Can the image of none in images in Docker be deleted

Tags: Docker

Posted by prismngp on Sat, 16 Apr 2022 19:16:13 +0930