Detailed explanation of image layering technology in Docker

As early as when the container did not appear, there were still many workers carrying goods on the dock. After the container appeared, there were more non-workers on the dock, and the container handling mode was simpler and more efficient. There are other Advantages, such as: the goods are mostly packed in containers, which can prevent the goods from affecting each other before. And if you need to transfer to another terminal, you can directly transport it to another container after you have the container, which can completely ensure that the goods inside are relocated as a whole, and the goods themselves will not be damaged. Then docker image also plays a very important image in the IT industry.

  what is a docker image

  It is to package the business code and the runtime environment as a whole

  How to create a docker image:

  Now there are a large number of images in the docker official shared warehouse, so we can directly pull the most basic images from the shared warehouse, because these mirrors are maintained by the original factory and can be updated and repaired immediately.

  Dockerfile

  If we want to customize these images, we can write a Dockerfile , then re- build , and finally package it into an image. This method is the most recommended method, including when we go to the enterprise to practice the application in the future. This method is also recommended .



 

  Commit :

  Of course, there is another way, which is to start a container through an image, then operate it, and finally commit an image through the commit command , but this method is not recommended, although the commit command is like a mode of operating a virtual machine, but After all, a container is a container, it is not a virtual machine, so everyone still has to adapt to the habit of customizing these images with Dockerfile .

  The concept of mirroring is mainly to package the operating environment and business code into mirroring. The focus of our class is to understand the layering technology of mirroring. Let's first look at an image of an Ubuntu system.



 

  We can mirror and layer many layers , and they all have sizes and IDs , we can see that there are 4 layer ID numbers here , and finally this mirror is composed of their layers , and this mirror is read-only, It cannot write data into it. What if it wants to write data? We will start a container layer on the image , which is actually equivalent to starting the image as a container, then at the container layer, we can write.



 

  For example, if we want to add a layer to the Ubuntu system, we can only continue to superimpose it on it. These tasks are actually realized by the mechanism under cow and the writing library.

  submirror



 

  When downloading, only the top layer of the submirror will be downloaded, because other layers already exist, so it can save space.

  parent image



 

最为典型的就是镜像的分层技术——aufs



 

  AufsAnother Union File System的缩写,支持将多个目录挂载到同一个虚拟目录下。

  已构建的镜像会设置成只读模式,read-write写操作是在read-only上的一种增量操作,固不影响read-only层。

这个研究有一个好处,比如我们现在可以看到手机里面的APP,在命令里面都会用APP字段下回来,在下回来之前它就是一个静态的,我们没有往里面写东西,但是我们启动起来以后,我们就可以往里面写东西,进行各种各样的操作。但是如果我们把它关掉了以后,或者删除了以后,它的这个镜像是存在远端的,所以在这个镜像里面是不会去修改的。并且这样也会有一个非常好的地方,这个场景非常适合我们去实现测试环境,因为我们的测试环境经常会有一个操作就是灌数据,我们可以提前把这个镜像数据打包到测试里面,那么这个镜像软件里面包含了,最上面是nginx,比如它里面会有一些数据,我们可以在往上面打一层数据,打完之后把它起成一个容器就可以去测试,测试完之后这个容器里面会生成各种各样的数据,也就是脏数据,这样的话,我们就可以把这个容器删掉,删掉以后我们镜像里面的容器是不会受影响的。如果说它想再创建一套,我们可以把这个镜像再启一个容器,就可以是一个一模一样的,并且是一个干净的环境。

 

文章来源:麦子学院

原文链接:http://www.maiziedu.com/wiki/cloud/dockerimage/

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326551323&siteId=291194637