In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you what are the knowledge points of Docker image, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
First, a simple understanding of Dockerfile
Dockerfile is a file used to build an Docker image and is a script made up of a series of commands and parameters.
To put it simply: Dockerfile is the source code of the image.
We pull an image of Tomcat before, and we can also see what its Dockerfile looks like:
Let's just click in and have a look:
We can find FROM openjdk:8-jre in the first line of Dockerfile, so we can be sure that the Tomcat image pulled in DockerHub must have a Java environment!
Let's not talk about how to read / write Dockerfile files here, just understand that Dockerfile is the source code of the image.
To put it simply: through the Dockerfile file, you can know exactly how the image we pulled down is built.
Second, remove the doubts about the mirror image.
We know that Docker Hub has many commonly used images, such as Centos. Let's go to pull and come down and see what the Centos in Docker looks like:
What we can find is that Tomcat's SIZE is even bigger than Centos! But according to our conventional thinking, the image of Centos may be 3 or 4GB (now 200m), and the image of Tomcat may be 200m (now 400m). Why is that?
If we take a closer look at pull, we can see that pull will pull down many layers of images:
After the full pull, if we use docker images, we can only see the final image:
If we use the docker images-a command, we can find out all the middle-tier images:
Ideal effect: (in addition to tomcat and centos, the image list should also be interspersed with images named)
Unfortunately: the blogger has never measured the effect, that is, the image that is not in my image list (suspected to be a version problem, my version is Docker version 18.09.1 Magi Centos version is CentOS Linux release 7.3.1611. If you know the specific reason, please tell me under the comments section)
Emmm, which we can look at with the history command, shows that Tomcat contains many mirror layers.
You can also find one thing: there are as many mirror layers as there are commands in Dockerfile (I don't believe you count)
Having said so much, I just want to let you know that the image we pulled down is actually made up of a lot of middle-tier images.
Combined with our previous introduction to Docker, why can it be so simple? When solving the problem of jam during Tomcat startup, what we can find is that we can use basic commands such as cd, ls, but not the vi command (I need to download it myself).
We can infer that the images under pull are composed of many layers of images [these images are all condensed (even the vi command is not supported)]
Because the Tomcat image requires more underlying environments than the Centos image, the SIZE of the Tomcat image is larger than that of Centos
Third, the characteristics of Docker image
With regard to Docker mirroring, it has the following characteristics:
Generated by Dockerfile
Present a hierarchical structure
Each layer of image contains: image file and image json metadata information
3.1 Mirror presentation hierarchy
The federated file system (UnionFS) is the technical basis for implementing Docker mirroring. AUFS (Another Union File System or Advanced Multilayered Unification File System) is generally used in Docker (it depends on what system the host uses).
When searching for Chinese materials, you will often find similar explanations:
AUFS is a kind of Union FS, which simply means "supports mounting different directories to a file system under the same virtual file system". AUFS supports setting read-only (Rreadonly), read-write (Readwrite) and write (Whiteout-able) permissions for each member directory. Union FS can mount the Branch of a Readonly and the Branch of a Writeable together under the same file system.
It makes me confused. . Later, I went to the official document to introduce AUFS:
AUFS is a union filesystem, which means that it layers multiple directories on a single Linux host and presents them as a single directory. These directories are called branches in AUFS terminology, and layers in Docker terminology
To put it bluntly, it can be understood that the image of Docker is based on the federated file system, which supports the modification information in the file system as a submission and overlaid layer by layer, and what the outside world sees is the outermost image. (for example, only Tomcat images can be seen in the outside world, and there are many layers of images superimposed in the middle)
(just to illustrate with AUFS, Docker actually supports many storage drivers, such as devicemapper,overlay2 (14.04.4 or higher of Ubuntu, 16.04 or later), overlay,zfs
Https://docs.docker-cn.com/engine/userguide/storagedriver/selectadriver/
3.1.1 Image inheritance (sharing)
Docker images can be inherited through layering.
For example, Dockerfile image of hello-world, FROM scratch image, and scratch is a basic image in Docker.
FROM scratch
COPY hello /
CMD ["/ hello"]
The Dockerfile image of Centos is also an FROM scratch image:
FROM scratch
ADD centos-7-docker.tar.xz /
LABEL org.label-schema.schema-version= "1.0"\
Org.label-schema.name= "CentOS Base Image"\
Org.label-schema.vendor= "CentOS"\
Org.label-schema.license= "GPLv2"\
Org.label-schema.build-date= "20181205"
CMD ["/ bin/bash"]
Then Centos image and hello-world share the same basic mirror layer scratch, which improves the storage efficiency.
For another example, let's say we have a Centos image with a size of 202m. Then, based on the Centos image, we manually add a Tomcat to it (assuming the size of the Tomcat is 300m) to generate an image with a total size of 502m.
If you simply add up the size of the two images: 202M+502M=704M, but due to the existence of image reuse, the actual amount of disk space occupied is: 202M+300M=502M
AUFS uses the Copy-on-Write (CoW) strategy to maximize storage efficiency and minimize overhead.
If you want to know more about COW, read the article I wrote earlier:
COW cow! Learn about the Copy On Write mechanism.
CopyOnWriteArrayList you do not know, how to get offer?
3.2json file
The mirrored json file in each layer of Docker plays a very important role, and its main functions are as follows:
Record the contents related to container dynamic information in Docker image
Record the real differences between father and son Docker images
Make up for the integrity of Docker mirror content and the lack of dynamic content.
Docker mirrored json files can be thought of as mirrored metadata information
These are all the contents of the article "what are the knowledge points of Docker Mirror?" Thank you for your reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.