Docker learning (IV) docker image

Xiao, ry 2022-01-26 23:44:48 阅读数:79

docker learning iv docker image

What is a mirror image

Image is a lightweight 、 Executable standalone package , It is used to package software running environment and software developed based on running environment , It contains the content needed to run a software , Including code 、 Runtime 、 library 、 Environment variables and profiles .

UnionFS( Federated file system )

UnionFS ( Federated file system ) : Union file system (UnionFS) It's a kind of layering 、 Lightweight and high performance file system , It supports the modification of the file system as a stack of layers submitted at one time , At the same time, you can mount different directories to the same virtual file system (unite several directories into a singlevirtualfilesystem).Union The file system is Docker The foundation of the mirror . Images can be inherited by layering , Based on the basic image ( No father image ) Can make a variety of specific application image .

characteristic : Loading multiple file systems at once , But from the outside it looks like , Only one file system can be seen , Joint loading will stack up all layers of file systems , In this way, the final file system will contain all the underlying files and directories

Docker Image loading principle

docker The image of is actually composed of file systems layer by layer , This hierarchical file system is UnionFS.

bootfs(boot file system) It mainly includes bootloader and kernel, bootloader Mainly boot loading kernel, Linux It will load when it is just started bootfs file system , stay Docker The bottom of the image is bootfs. This floor is typical of Linux/Unix The system is the same , contain boot Loader and kernel . When boot After loading, the whole kernel is in memory , At this time, the right to use the memory has been bootfs To the kernel , The system will also uninstall bootfs.

rootfs (root file system), stay bootfs above . Contains typical Linux In the system **/dev, /proc, /bin, /etc Etc. standard directories and documents .rootfs Is a variety of different operating system distributions , such as Ubuntu**,Centos wait .
 Insert picture description here

The number of virtual machines we usually install Centos There are several G , Why? docker It's here 230m
 Insert picture description here

For a streamlined OS, rootfs It can be very small , Just include the most basic commands 、 Tools and libraries will do , because The bottom layer directly uses Host Of kernel, You only need to provide rootfs That's it . about Different linux Distribution version , bootfs Basically consistent , rootfs There will be differences , So different distributions can be shared bootfs.

Layered mirror

Looking at the image, you can see tomcat A very large , Yes 680M, Why is that ?
 Insert picture description here

because tomcat You need to install jdk8, and jdk8 Installed in the centos On , So what you see tomcat Your image will be larger , It contains the required environment configuration .
 Insert picture description here

In order to pull tomcat Image as an example , You can see docker It seems that the image is downloaded layer by layer .
 Insert picture description here

Why? Docker The mirror should adopt this hierarchical structure

One of the biggest benefits is —— Shared resources
such as : There are multiple images from the same base The image is built , Then the host only needs to save one copy on the disk base Mirror image , At the same time, only one copy needs to be loaded in memory base Mirror image , You can serve all containers . And every layer of the image can be shared .


Docker Images are read-only , When the container starts , A new writable layer is loaded on top of the image , This layer is often called the container layer , Below the container layer is called the mirror layer .

Docker Mirror image Commit operation

docker commit Commit the container copy to a new image
docker commit -a=" author " -m=" Description information submitted " Containers ID The target mirror name to create :[ Tag name ]

Case presentation :

  1. from Hub Upload and download tomcat Mirror to local and run successfully
     Insert picture description here

Errors may occur :
 Insert picture description here

View the running container :
 Insert picture description here

Enter the container :
 Insert picture description here
You can see that there is webapps, Enter this folder to view , It's empty
 Insert picture description here

Back to the next level , You can see there's one webapps.dist, It contains webapps Documents normally required , Move the files inside to webapps Next , Or delete webapps, take webapps.dist Renamed webapps.
 Insert picture description here

Refresh web page , According to the normal :
 Insert picture description here

Background operation : Don't print logs

docker run -d -p 6666:8080 tomcat
-p Host port :docker Container port
-P: Randomly assign ports
i: Interaction
t: terminal
  1. Delete the document in the container
     Insert picture description here
     Insert picture description here

  2. Current tomcat The running instance is a container without document content , Use it as a template commit A no docs Of tomcat New image mytest/tomcat02
     Insert picture description here
     Insert picture description here
     Insert picture description here

  3. Start our new image and compare it with the original

​ 1) Start original tomcat The new container has docs

​ 2) start-up mytest/tomcat02 The new container has no docs

copyright:author[Xiao, ry],Please bring the original link to reprint, thank you.