superstator
superstator

Reputation: 3228

Cannot delete docker image

While setting up a new build machine (CentOS 7, Docker CE 17.12.0-ce), I did a simple test:

docker run -it --rm ubuntu bash

Which worked fine, but now I can't remove the Ubuntu image.

[build ~]$ docker image rm ubuntu
Error: No such image: ubuntu
[build ~]$ docker image rm ubuntu:latest
Error: No such image: ubuntu:latest
[build ~]$ docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              0458a4468cbc        24 hours ago        112MB
[build ~]$ docker rmi 0458a4468cbc
Error: No such image: 0458a4468cbc

It's not being used by any containers (not that that's the error anyway):

[build ~]$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[build ~]$

I even tried the nuke-from-orbit approach:

[build ~]$ docker rmi $(docker images -q)
Error: No such image: 0458a4468cbc

And restarting the docker daemon:

[build ~]$ sudo systemctl restart docker
[build ~]$ docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              0458a4468cbc        24 hours ago        112MB
[build ~]$ docker rmi 0458a4468cbc
Error: No such image: 0458a4468cbc

What gives? Not that it really matters that the ubuntu image is there, I just don't understand why I can't clean it up.

Update

I tried pulling the image again, and, well:

docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
Digest: sha256:e27e9d7f7f28d67aa9e2d7540bdc2b33254b452ee8e60f388875e5b7d9b2b696
Status: Downloaded newer image for ubuntu:latest
[build ~]$ docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              0458a4468cbc        25 hours ago        112MB
ubuntu              latest              0458a4468cbc        25 hours ago        112MB
[build ~]$ docker image rm ubuntu
Untagged: ubuntu:latest
[build ~]$ docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              0458a4468cbc        25 hours ago        112MB
[build ~]$

Update 2

Tried the same basic steps with a brand new CentOS 7 1708 install and had no problems at all, so safe to say this is just a weird one-off corruption of something on this machine.

Question still is, how do I clean it up? Is there something on the filesystem I can just rm -rf and let docker start fresh?

Upvotes: 3

Views: 8601

Answers (4)

Dagoberto Marroquin
Dagoberto Marroquin

Reputation: 1

maybe you can use docker image rm -f <ID_IMAGE>

Upvotes: -2

user07
user07

Reputation: 1

You can try selecting the version of the operating system you want to delete, example:

docker image rm -f ubuntu:18.04

Upvotes: 0

&#214;mer Sezer
&#214;mer Sezer

Reputation: 2669

I encountered similar thing, when I used rm -f, it was not working (could not delete)

docker rm -f <ImageId> 

I restarted Docker Engine and I used the following command, it works.

docker image prune -f -a

Upvotes: 2

superstator
superstator

Reputation: 3228

While setting up this system I had originally installed an old version of docker available from the standard CentOS repositories (yum install centos) instead of adding the docker repositories and installing docker-ce. Even though I'm on the latest version now, the old one must have introduced some bad data in /var/lib/docker before I upgraded. In the end I just deleted all the local image and container data and started over:

sudo systemctl stop docker
sudo rm -rf /var/lib/docker
sudo systemctl start docker

Everything is working normally now.

Upvotes: 12

Related Questions