Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the differences between layer and image in docker?

Tags:

docker

image

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?

like image 577
Chris Tien Avatar asked Sep 23 '15 11:09

Chris Tien


People also ask

What are Docker layers and how do they work?

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.

What is the difference between Docker image and Docker container?

Docker Image is an executable package of software that includes everything needed to run an application. This image informs how a container should instantiate, determining which software components will run and how. Docker Container is a virtual environment that bundles application code with all the dependencies required to run the application.

How do I create a docker image?

A Docker image consists of several layers. Each layer corresponds to certain instructions in your Dockerfile. The following instructions create a layer: RUN, COPY, ADD. The other instructions will create intermediate layers and do not influence the size of your image. Let’s take a look at an example.

What are the dockerfile instructions that modify the image filesystem?

The Dockerfile instructions that modiy the image filesystem namely are ADD, COPY and RUN. Furthermore, a Docker image merely is a configuration object stored in JSON format. Such a JSON object contains, besides to image metadata like the CMD instruction, an ordered list of layers. Running docker image inspect will print those layers.


1 Answers

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
like image 149
Thomasleveil Avatar answered Oct 05 '22 19:10

Thomasleveil