6

I know that an image consists of many layers. for example, if u run "docker history [Image]", u can get a sequence of ids, and the ID on the top is the same as the image id, the rest IDs are layer ID.

in this case, are these rest layer IDs correspond to some other images? if it is true, can I view a layer as an image?

Chris Tien
  • 333
  • 2
  • 14

3 Answers3

4

Layers are what compose the file system for both Docker images and Docker containers.

It is thanks to layers that when you pull a image, you eventually don't have to download all of its filesystem. If you already have another image that has some of the layers of the image you pull, only the missing layers are actually downloaded.

are these rest layer IDs correspond to some other images?

yes, they are just like images, but without any tag to identify them.

can I view a layer as an image?

yes


show case

docker pull busybox
docker history busybox
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
d7057cb02084        39 hours ago        /bin/sh -c #(nop) CMD ["sh"]                    0 B
cfa753dfea5e        39 hours ago        /bin/sh -c #(nop) ADD file:6cccb5f0a3b3947116   1.096 MB

Now create a new container from layer cfa753dfea5e as if it was an image:

docker run -it cfa753dfea5e sh -c "ls /"
bin   dev   etc   home  proc  root  sys   tmp   usr   var
Thomasleveil
  • 69,168
  • 10
  • 106
  • 102
0

Layers and Images not strictly synonymous. https://windsock.io/explaining-docker-image-ids/

When you pull an image from Docker hub, "layers" have "" Image IDs. When you commit changes to locally built images, these layers will have Images IDs. Until when you push to Dockerhub. Only the leaf image will have Image ID for all others users pulling that image you uploaded.

user3761555
  • 405
  • 2
  • 12
-1

From docker documentation:

A Docker image is a read-only template. For example, an image could contain an Ubuntu operating system with Apache and your web application installed. Images are used to create Docker containers. Docker provides a simple way to build new images or update existing images, or you can download Docker images that other people have already created. Docker images are the build component of Docker. Each image consists of a series of layers. Docker makes use of union file systems to combine these layers into a single image. Union file systems allow files and directories of separate file systems, known as branches, to be transparently overlaid, forming a single coherent file system.

One of the reasons Docker is so lightweight is because of these layers. When you change a Docker image—for example, update an application to a new version— a new layer gets built. Thus, rather than replacing the whole image or entirely rebuilding, as you may do with a virtual machine, only that layer is added or updated. Now you don’t need to distribute a whole new image, just the update, making distributing Docker images faster and simpler.

The way I like to look at these things is like backup types. We can create full backups and after that create incremental backups. The full backup is not changed (although in some systems to decrease restore time after each incremental backup the full backup is changed to contain changes but for this discussion we can ignore this case) and just changes are backed up in a separate manner. So we can have different layers of backups, like we have different layers of images.

EDIT: View the following links for more information:

Docker image vs container

Finding the layers and layer sizes for each Docker image

Community
  • 1
  • 1
AKJ88
  • 643
  • 1
  • 9
  • 19