Docker from entry to abandonment (3) Understand Docker image

1. Introduction to Docker images

1. Mirror concept

It is a lightweight, executable independent software package that contains everything needed to run a software. We package the application and configuration dependencies to form a deliverable runtime environment (including code, runtime required Libraries, environment variables and configuration files, etc.), this packaged runtime environment is the image image file.

Only through this image file can a Docker container instance be generated (similar to a new object in Java).

2. Layered mirroring

Taking our pull as an example, during the download process we can see that the docker image seems to be downloaded layer by layer

3. UnionFS (Union File System)

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.

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

4. Docker image loading principle:

The docker image actually consists of a layer-by-layer file system, the file system UnionFS at this level. The bootfs (boot file system) mainly includes the bootloader and the kernel. The bootloader is mainly used to boot and load the kernel. The bootfs file system is loaded when Linux is just started. 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.

 

5. Why does the Docker image use this layered structure?

One of the biggest benefits of image layering is that it shares resources, which is convenient for replication and migration, which is for reuse.

For example, if multiple images are built from the same base image, the Docker Host only needs to save one base image on the disk; at the same time, it only needs to load one base image in the memory to serve all containers. And each layer of the image can be shared.

Summary: 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".

 

 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 - adding, deleting, or modifying files only happen in the container layer. Only the container layer is writable, and all image layers below the container layer are read-only.

2. Docker image commit operation case

1. docker commit commits a copy of the container to make it a new image

2. docker commit -m="Submitted description information" -a="author" container ID The name of the target image to be created: [label name]

For example: the original default Ubuntu image does not carry the vim command

As mentioned before: docker will only load the basic liunx kernel, so Ubuntu is only 72.8MB, which makes it unusable when we use vim, so we have to install the "components" you want on this kernel.

1) Install the corresponding environment: apt-get update

 2) Install vim: apt-get -y install vim

3. Commit our own new image

We found that myubuntu with components should be bigger because it adds functions, which is the beauty of docker.  

4, the new image and compared with the original

 

1. The official website is the default downloaded Ubuntu without vim command

2. The image built by our own commit has newly added vim function and can be used successfully.

Summary: Image layering in Docker supports the creation of new images by extending existing images. Similar to Java, it inherits from a Base base class, and then extends it as needed. The new image is generated layer by layer from the base image. Every time a piece of software is installed, an additional layer is added to the existing image.

 

Guess you like

Origin blog.csdn.net/OMGcome/article/details/123760482