Docker practical experience (2) Mirror construction, mirror warehouse, compression, import

insert image description here

Write an article three times, remove impurities, and refine dry goods. This is a series of blogs with temperature.

Build the image: docker commit

Once the running virtual machine fails, many operations on it will be invalidated and you have to start all over again. But there are always smart people, so virtual machines can take snapshots.
Then when using the container, if the container fails, it does not mean that more than half of the previous work is lost (how much is left, the next article will explain the storage volume.) This is like I built a three-dimensional system based on docker The master and three-slave redis cluster, as soon as docker shuts down, my cluster will be rebuilt.

Building an image is as simple as one line of command and requires no network.

docker commit -m="镜像描述" -a="作者信息" 容器id 镜像名:版本号

Of course, there are other options to choose from, if needed: docker commit -h.


small tips

Why do you say that docker containers must be diligently backed up, because the risk of docker containers being deleted by mistake is higher than that of VMware, which is also the reason why I only used Ctrl+p+q to exit docker in the previous article, and exit improperly It will directly shut down the entire container for you.

Imagine a picture: You are developing on your "Iron Chain" container, and at this time, a short-sighted person misoperated when exiting, and the entire container was closed for you. Oh, exciting, do you choose to slap him, or slap him, or slap him?

If there is no backup, then it is useless for you to beat him a few times.


Image Layering and Union File Systems

Not to mention, let's take a look at a picture in the previous article, when running redis:
insert image description here

Look there are five Pull completes. What does this mean? The description is to download five things, and finally spell out a redis.

What's the benefit of this? If the building blocks are set up, why don't they fuse together? Think a little bit.

UnionFS (Union File System) : The Union File System (UnionFS) is a layered, lightweight and high-performance file system that supports changes to the file system as a commit to stack layer by layer, and can combine different The directories are mounted under the same virtual filesystem (unite several directories into a single virtual filesystem). The Union filesystem is the foundation of Docker images. Images can be inherited through layers. Based on the base image (without parent image), various specific application images can be created.


Docker image loading principle

If you don't understand it once, you can read it twice.

insert image description here

bootfs (boot file system) mainly includes bootloader and kernel. The bootloader is mainly to boot and load the kernel. When Linux starts, it will load the bootfs file system. The bottom layer of the Docker image is the boot file system bootfs. This layer is the same as our typical Linux/Unix system and contains the boot loader and kernel. When the boot is loaded, 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.

rootfs (root file system), on top of bootfs. It contains 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.

For a streamlined OS, the rootfs can be very small, and it only needs to include the most basic commands, tools and program libraries, because the bottom layer directly uses the host's kernel, and only needs to provide the rootfs. It can be seen that for different linux distributions, the bootfs is basically the same, and the rootfs will be different, so different distributions can share the bootfs.

insert image description here

The Docker image layer is read-only, and the container layer is writable. When the container starts, a new writable layer is loaded on top of the image. This layer is often referred to as the "container layer", and everything below the "container layer" is called the "image layer". All changes to the container, whether adding, deleting, or modifying files, only happen in the container layer.


Image repository && push image to repository

When you get to work, your mentor will teach you how to use your company's mirror repository.

The command to push the image to the warehouse is: docker push image name: [tags]

However, the mirror name here will have some domain names, which are related to the mirror warehouse. Different warehouses will have different domain names. Generally, the manual of the mirror warehouse will introduce it. If there is no introduction, you can ask your tutor or colleagues.


Compressed image: docker save

In addition to pushing the image to the remote repository, there is another way to save the image, which is to package the image into a compressed package.
That's why I don't talk about mirror repositories.

Generally, the compressed image command you see on the Internet is docker save 镜像名:版本号the same, so the packaged file will still be too large.
The first task of my internship was to package the docker image. I did the same at first, but before I packaged it all, I found that the space was almost occupied. So I turned to my mentor, who gave me a command:

docker save xxx:yyy | gzip -9 > zzzzz.tar.gz

Let me try again to see the size.

Not to mention that he is my mentor, he has experience! ! !

The internship is almost over. My tutor is really kind to me. This is the envy of my two friends haha.


Import image: docker load

The image was compressed earlier, for import here, otherwise why compress it.

The import command is also simple:

docker load < 镜像名.tar.gz

After importing:

docker images | grep xxxxx

I forgot to bring grep in the previous post. There are so many mirror images, if you really want to turn them one by one, it is estimated that my titanium alloy dog's eyes will be tired and blind. This trick is also taught by my tutor.

Guess you like

Origin blog.csdn.net/qq_43762191/article/details/124213403