Reputation: 14199
I'm trying to understand the following commands
docker image prune
docker image prune -a
According to the docs
docker image prune: Removes dangling images
docker image prune -a: Removes dangling and unused images`
I'm trying to understand the difference between a dangling and unused image.
According to this stackoverflow post, an unused image is an image that has not been assigned or used in a container.
So basically, if I run
docker pull hello-world
(having never executed the command docker run hello-world
)
Then the image for hello-world would be an unused image??
How are dangling images created then?
According to the above referenced stack overflow post, "a dangling image just means that you've created the new build of the image, but it wasn't given a new name. So the old images you have becomes the 'dangling image'."
What exactly does that mean? I.e, what does it mean to create a new build of the image? How do you create a new build of the image? What are untagged images?
Can someone give me an example of how a dangling image is created?
Upvotes: 2
Views: 2652
Reputation: 11280
Dangling image simply means you have an image, but it has no tags attached to it. (Prune unused Docker objects)
How do you reach it? by building an image with the same name and the same tag. That's the usual case, not the only one.
my.image.example.com
and tag it with latest
.my.image.example.com:lastest
This is very high level and abstracted description of what an image tag is;
Most if not all computer softwares are composed by a name and a version. For example, your OS might be Windows 10, OSX Catalina (14 Mojave), etc.
In the containers world, the image tag is used to address the version of the software. The image name - is the software itself.
When you download an image, you specify the image name and its "version" (which is, the tag). That's the common use-case. Tags can be used for many purposes; there can be many tags to a single image, but not a single tag that references multiple images.
I think Docker overview can be a good place to get some fundamental background of the platform
Upvotes: 3
Reputation: 137
Let's go one by one:
Then the image for hello-world would be an unused image??
Yes.
How are dangling images created then?
In your situation, you can create a new version of same image or you can untag your image, then you have a dangling image.
What exactly does that mean? I.e, what does it mean to create a new build of the image? How do you create a new build of the image?
You can build image anytime by running docker build
command or even pull newer version docker pull
from somewhere.
What are untagged images?
Each image has a tag as is stated in documentation you can retag images with following command:
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
When you remove tagging or build image again, usually you will end up with untagged image.
Can someone give me an example of how a dangling image is created?
Well, i would say it very simply, just untag any image and you have a dangling image.
At the end, here is duplicated link for this issue: Same question with answer
Upvotes: 1
Reputation: 389
Suppose you build an image based on a Dockerfile with the tag "asool/user-service":
docker build -t asool/user-service .
The image is succesfully built and has ID "5e8d606c6dcc". Consequently, you change the content of that Dockerfile, e.g. you add a line RUN apk add vim
. Then, you build an image with the same tag "asool/user-service":
docker build -t asool/user-service .
A new image is created, tagged "asool/user-service", having another ID. Although a new image came to existence, the old image with ID "5e8d606c6dcc" still exists. That image lost its tag, its name and most likely its purpose. This image is called a dangling image.
Source: Dockerfile Tutorial by Example - ( Part I - Basics )
Upvotes: 2