Docker visualization and mirroring

Docker visualization and mirroring

One, visualization

carry

Docker graphical interface management tool provides a background panel for us to operate!

docker run -d -p 8081:9000 --restart=always -v /var/run/docker.sock:/var/run/docker --privileged=true portainer/portainer
本地用这个:不然会报错Failure Cannot connect to the Docker daemon at unix:///var/run/docker.sock.
docker run -d -p 8081:9000 --restart=always -v "/var/run/docker.sock:/var/run/docker.sock" --privileged=true portainer/portainer

Visit: http://ip:8081/
Insert picture description here
Insert picture description here

Insert picture description here
Insert picture description here

Two, Docker image

What is mirror

Mirror is a lightweight, executable, independent software guarantee, used to package the software operating environment and software developed based on the operating environment. It contains all the content needed to run a certain software, including code, runtime libraries, and environment variables. And configuration files.

All applications and environments can be directly packaged as a docker image and run directly.

1. Docker image loading principle

UnionFs (Union File System)

When we download, we see layers of downloads that are this.

UnionFs (Union File System): The Union File System (UnionFs) is a hierarchical, lightweight and high-performance file system. It supports the modification of the file system as one submission to superimpose layer by layer, and at the same time, different The directories are mounted under the same virtual file system (unite several directories into a single virtual filesystem). The Union file system is the basis of Docker images. Mirroring can be inherited by layering. Based on the basic mirroring (without parent mirroring), various specific application mirroring can be made.

Features: Load multiple file systems at the same time, but from the outside, only one file system can be seen. Joint loading will superimpose all layers of file systems, so that the final file system will contain all the underlying files and directories.

Docker image loading principle

The docker image is actually composed of a layered file system, this layered file system UnionFS.
Boots (boot file system) mainly includes bootloader and Kernel. Bootloader mainly boots and kernel. When Linux starts, it will add bootfs file system. The bottom layer of Docker image is boots. This layer is the same as our typical Linux/Unix system, including the boot loader and the kernel. When the boot load is complete, the entire kernel is in the memory. At this time, the right to use the memory has been transferred from the bootfs to the kernel, and the system will also unload the bootfs at this time.

rootfs (root file system), above bootfs. Included are standard directories and files such as /dev, /proc, /bin, /etc in a typical Linux system. Rootfs is a variety of different operating system distributions, such as Ubuntu, Centos and so on.
Insert picture description here

2. Hierarchical understanding

We can go to download a mirror, pay attention to the log output of the download, you can see that the download is layer by layer.

  • Thinking: Why does Docker image adopt this layered structure?

The biggest benefit, I think, is resource sharing! For example, if multiple images are built from the same base image, then the host only needs to keep one base image on disk, and only one base image needs to be loaded in the memory, so that it can serve all containers. , And each layer of the mirror can be shared.

understanding:

All Docker images start from a basic image layer. When modifying or adding new content, a new image layer will be created on top of the current image layer.

To give a simple example, if you create a new image based on Ubuntu Linux 16.04, this is the first layer of the new image; if you add a Python package to the image,
a second image layer will be created on top of the base image layer. ; If you continue to add a security patch, the third mirroring layer will be created as it currently contains 3 mirroring layers, as shown in the figure below (this is just a very simple example for demonstration).

While adding additional mirror layers, the mirror always remains a combination of all current mirrors. It is very important to understand this. The following figure shows a simple example, each mirror layer contains 3 files, and the mirror contains 6 files from two mirror layers.
Insert picture description here
Insert picture description here
The mirror layer in the above picture is slightly different from the previous picture. The main purpose is to facilitate the display of files
. The picture below shows a slightly complicated three-layer mirror. From the outside, the entire mirror has only 6 files. This is because of the top layer. File 7 in is an updated version of file 5

Insert picture description here
In the case of the language type, the files in the upper mirror layer overwrite the files in the lower mirror layer. This allows the updated version of the file to be added to the mirror as a new mirror layer.

Docker uses the storage engine (the new version adopts the snapshot mechanism) to implement the mirror layer stack, and ensures that the multiple mirror layers are externally displayed as a unified file system.

Storage introductions available on Linux include AUFS, Overlay2, Device Mapper, Btrfs, and ZFS. As the name suggests, each storage engine is based on its counterpart in Linux.
Software system or block device technology, and each storage engine has its own unique performance characteristics.

Docker only supports windowsfilter a storage engine on Windows, which implements layering and CoW [1] based on the NTFS file system.

The following figure shows the same three-layer mirroring as the system display. All mirror layers are stacked and merged to provide a unified view to the outside world.
Insert picture description here
Insert picture description here
Docker images are read-only. When the container starts, a new writable layer is loaded on top of the image. This layer is called the container layer, and the image layer below the container layer

Docker uses the storage engine (the new version adopts the snapshot mechanism) to implement the mirror layer stack, and ensures that the multiple mirror layers are externally displayed as a unified file system.

Insert picture description here

3. Commit to submit the image

docker commit # 提交容器成为一个新的副本
docker commit -m="提交的描述信息" -a="作者" 容器id 目标镜像名:[TAG]
docker images
docker run -it -p 8080:8080 tomcat

Copy all the files in webapps.dist to webapps, where -r must be present, which means that the directory is copied recursively
Insert picture description here

docker commit -a="latteitcjz" -m="root" 当前容器的id tomcat02:1.0

If you want to save the current state of the container, you can submit it through commit and get an image, just like we use a snapshot of a virtual machine.

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_43803285/article/details/114456298