What are Docker none: none images?

I bring to your attention a translation of the article What are Docker none: none images? from the Project Atomic blog.


The last few days I spent on exercises with Docker images . To explain what they are and what they can do, I write this post in which I pose questions::


  1. What are Docker images ?:
  2. What are dangling images?
  3. Why do I see a bunch of images when I do ?:docker images -a
  4. What is the difference between docker imagesand docker images -a?

Before I start answering questions, remember that there are two kinds of images : good and bad.:


Good looks :


To understand them, you need to understand how the Docker image file system works, and how image layers are organized. This post will use the Fedora image as an example. The Docker daemon is running on the laptop, and I'm going to download the fedora image from the docker hub.


docker images


In this screenshot, it docker imagesshows fedora:latest, and docker images -aalready two images fedora:latestand . If you use Docker, you have noticed that the number of images grows exponentially with the number of downloaded images.::


What are the images for ? To understand this, you need to know how the layers of the Docker file system are organized. Each docker image consists of layers, and the layers have parent and child relationships with other layers. All layers of the docker file system are stored in by default . In Docker terminology, it is called a graph database. The example consists of two layers, they can be found in .:/var/lib/docker/graphfedora:latest/var/lib/docker/graph


docker graph


IMAGE IDcorresponds to a layer in the directory /var/lib/docker/graph. When you do docker pull fedora, the image loads one layer at a time. Docker first loads the layer 48ecf305d2cfand marks it , as this is just one of the image layers . In Docker terminology, it is called an intermediate image because of the option .:fedora:latest-a


Next, Docker loads the layer ded7cd95e059and marks it fedora:latest. The fedora: latest image consists of these two layers, forming a parent-child relationship.


parent child


To verify the existence of a parent-child relationship, we can check the layer JSON file ded7cd95e059.


parent json


All right! Now we understand what the images mean . These are intermediate images that can be seen using . They do not overflow the hard drive, but take up a lot of space in the output of the command. And it’s quite difficult to understand what they are related to.:docker images -a


We answered (1), (3) and (4). Let's shed some light on (2).


The bad :


Other images are separate images that can overflow the hard drive.:


In the Java and Golang programming languages, a separate block of memory is a block without links from anywhere in the code. The garbage collection system of such languages ​​periodically marks blocks as separate and returns them to the heap, after which these blocks are available for future use. Like them, the separate layer of the Docker file system is something unused and without links from any images. Therefore, we need a way to tell Docker to clean these isolated images.


We already know what it means to . It is said above that these are intermediate images. However, in the absence of images in the output , there are intermediate images available for cleaning. Where do they come from?:docker images -a:docker images


These intermediate images are the results of the teams docker buildor pull. As a specific example,


Let's build the image hello_worldusing our previously uploaded fedora base image. We will hello_worldbuild the image using the Dockerfile.


hello world


As shown in the top screenshot, we successfully built the image hello_worldusing the Dockerfile.


Time passed after building the image hello_world, and a new version of Fedora was released. Let's download the new Fedora image.


new fedora


I got a new Fedora image. Now I want to build an image hello_worldwith the new Fedora. Let's assemble the image again with the same Dockerfile.


dangling


If you digress and check, the old Fedora image has an IMAGE ID ( ded7cd95e059) and the new Fedora image from the screenshot above has an IMAGE ID ( 5c6d07393f9f), which means that the Fedora image has been updated successfully. The important thing to note in the top screenshot is the image .:


If you remember, the images indicated in this are intermediate (good) images, but this image is the usual docker image. This is an isolated image and needs to be cleaned. When the image was rebuilt using the Dockerfile, its reference to the old Fedora became unmarked and detached.:docker images -a:hello_world


This command can be used to clean isolated images.


docker rmi $(docker images -f "dangling=true" -q)

Docker does not currently have an automatic garbage collection system. It will be cool to have one. In the meantime, this command can be used to manually collect garbage.


Also popular now: