Docker is a kind of container, what is a container? In software development, we often encounter "This program is obviously no problem on my computer, why is there a problem on the customer's computer?" This is because the software and hardware of each computer are inconsistent.
Is there a unified, virtual software and hardware platform on which the software is developed and sent to customers, who can run programs directly on this platform? Yes, this is the container. There are many kinds of containers, and Docker is the better one.
Compared with VMware, Docker is a lightweight software that runs fast.
Before using Docker, you need to understand two concepts: Image and container, that is, image and container. The image is an environment package, which can be moved to any Docker platform to run. The container is an instance of an image, and one image can start multiple containers.
In simple analogy, the image is like a Word software, which is released by the manufacturer and you cannot modify it; the container is that you start the Word software, you can start multiple Word software, and write different documents in each Word software.
The core of Docker is the "union file system". What does it mean?
Suppose you have 2 directories: lower and upper, they can be merged into a new directory merged, the content is as follows:
What is the principle of merger? The upper directory has higher priority and can overwrite the lower directory. The lower directory is read-only, and the upper directory is readable and writable. This rule can be parsed more specifically:
① If the file name and directory are different, the files and directories in the lower and upper directories are merged into the merged directory according to the original structure;
② The file names are the same, only the files in the upper layer are displayed:
As shown in the above figure, there are same.txt files in the lower and upper directories and the lower directory dir_A, but when merged into the merged directory, only upper is displayed, while lower is hidden.
③ If the directory names are the same, merge the directories into one directory:
As shown in the above figure, there are dir_A directories in the lower and upper directories. All files in the directories and directories are merged into the merged dir_A directory. If there are files in the directory with the same name, only upper ones will also be displayed, as shown in the above figure. same.txt file.
When reading a file, if there is the file in the upper directory, read it from the upper directory; otherwise, read it in the lower directory.
When creating, modifying, or deleting files, only the upper directory is affected, and the lower directory is read-only and is not affected.
In Docker, the image provides read-only files in the lower layer; the container provides readable and writable files in the upper layer, as follows:
When we start a container, we create a readable and writable upper file system based on the lower file system provided by the image.
We can start multiple containers, that is, create multiple upper layer file systems, and the upper layer file systems of these containers do not affect each other.
Recommended Posts