preface
Docker series:
If you have not installed Docker, please refer to the last part of this article. From now on, we must follow my Demo to knock it again, and the impression will be more profound. Come on!
- Why learn Docker
- Docker basic concepts
What is a mirror image
- An image is an executable software package that runs independently. Contains files and dependency packages necessary for application operation;
- An image can be understood as a class or template, as long as it is used out of the box in the context of a container.
Docker image loading principle
What is a UnionFS
Before introducing UnionFS let’s take a look at bootfs and rootfs:
bootfs(boot file system)
Bootfs contains the boot Loader and kernel operating systems. The user will not modify the file system. Bootloader mainly boots the kernel. When Linux is started, the bootfs file system is loaded. After the startup, the entire Linux kernel is loaded into the memory, and the Bootfs is uninstalled to release the memory.
rootfs(root file system)
Rootfs contains the typical directory structure, including /dev, /proc, /bin, /etc, /lib, /usr, and/TMP, plus all configuration files, binaries, and libraries needed to run the user application. This file system is different in different Linux distributions. And users can modify the files. The Roofs of Linux systems are first mounted in read-only mode at startup, and then changed to read-write mode after startup, and then they can be modified.
UnionFS(Union File System)
UnionFS, which translates to union file system, was developed by the State University of New York at Stony Brook in 2004. It can mount the contents of multiple directories (also called branches) jointly into the same directory, but the directories are physically separated. UnionFS allows both read-only and read-write directories to coexist. UnionFS can be used in many ways, such as merging the home directories of different file systems on multiple disk partitions or merging several CDS into a single CD directory (archive). In addition, with copy-on-write functionality, UnionFS can merge read-only and read-write file systems together, virtually allowing changes to the read-only file system to be saved to the writable file system.
Docker image acceleration principle
Docker images are actually made up of a layer of file systems, called UnionFS, as shown below:
When you start the container with Docker Run, you actually add a new writable layer on top of the image. This writable layer is also called the container layer.
This is the image package I have downloaded locally. You can see that the size of the centos image package is only 209M. Usually, we install centos on virtual machines with several GIGABytes. In this case, the centos image file is only a minimal version of rootfs. It shares the kernel with the underlying system, so it can run a centos with only 200 MB. The size may vary slightly from distribution to distribution.
We summarize the principle of image acceleration, because Docker images are layered, so when loading an image, the image layers required by the image will be loaded in sequence from bottom to top. During loading, if the current mirror layer already exists, the current mirror layer will be skipped. For example, if you have downloaded the MySQL image and need to download the Tomcat image, the CentOS image layer will be skipped when downloading the Tomcat image.
Layered understand
When we use Docker Pull to download the image, we can see that the image is downloaded layer by layer, as shown below:
Elasticsearch: docker Image Inspect ElasticSearch
The Docker image layer is shown below:
Docker is responsible for stacking these image layers. Each Docker image starts 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, as shown below:
In actual combat
Submit mirror
The original Docker Centos image does not have VIM command, we make a Centos image with VIM.
- Pull the mirror image, and you can see that the mirror image is also pulled layer by layer;
docker pull centos
Copy the code
- Start centos mirroring in daemon mode.
# View all mirrors
docker images
Start centos in background mode
docker run -d -it --name centos01 centos:latest
Copy the code
- Enter the container and check whether the original image supports the vim command.
Check the container information
docker ps
Enter the container interactively
docker exec -it d86647f84f18 /bin/bash
# validation
vim
Copy the code
- Exit the interactive mode by installing the VIM command in the container.
# install VIM;
yum -y install vim
Exit interactive mode
exit
Copy the code
- Make the image of Centos with VIM and start verification;
#docker commit -m=" description of information "-a=" author" container Id TAG TAG
Submit an image named vimcentos version 1.0
docker commit -m="With VIMCentos image" -a="wtz" d86647f84f18 vimcentos:1.0
Verify whether VIM is supported
docker run -d -it - the name vimcentos vimcentos: 1.0
Copy the code
Push the image to ali cloud mirror warehouse
- Create a namespace;
- Login Ali Cloud mirror;
docker login --username=17177* * * *@qq.com registry.cn-shanghai.aliyuncs.com
Copy the code
- Label the image;
docker tagThe version number] [ImageId] registry.cn-shanghai.aliyuncs.com/wtzdockerhub/wtzdockerhub: [image
Copy the code
- Upload image;
dockerPush registry.cn-shanghai.aliyuncs.com/wtzdockerhub/wtzdockerhub: [the mirror version number]
Copy the code
Docker installation
System requirements
Docker supports the 64-bit version of CentOS 7/8, and the kernel version must be at least 3.10. CentOS7 meets the requirements of the minimum kernel. However, due to the earlier kernel version, some functions (such as the overlay2 storage layer driver) cannot be used, and some functions may be unstable.
Uninstall the previous version
The old version of Docker is called Docker or docker-engine. Use the following command to uninstall the old version:
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
Copy the code
Install using yum
Resources to prepare
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Copy the code
The allocation of resources
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Copy the code
Docker installation
sudo yum -y install docker-ce
Copy the code
Docker start
sudo systemctl enable docker
sudo systemctl start docker
Copy the code
Image package acceleration
In view of the domestic network problems, it is very slow to pull the Docker image, so we need to configure the accelerator to solve the problem. The following three mirror configurations can be adopted in China:
- Ali Cloud Accelerator (click the management console -> Login account (Taobao account) -> right Mirror center -> Mirror Accelerator -> Replication address)
- Netease Cloud Accelerator https://hub-mirror.c.163.com
- Baidu cloud accelerator https://mirror.baidubce.com
Check whether the image address is configured in the docker.service file.
systemctl cat docker |grep'\-\-registry\-mirror'
Copy the code
If the command has output, run systemctl cat docker to see where ExecStart= appears, modify the corresponding file contents to remove the –registry-mirror parameter and its value, and follow the following steps to configure it. If the above command does not produce any output, you can write the following to /etc/docker-daemon. json (if the file does not exist, please create a new file) :
cd /etc/docker/
touch daemon.json
{
"registry-mirrors": [
"https://hub-mirror.c.163.com".
"https://mirror.baidubce.com"
]
}
Copy the code
Restart the service
sudo systemctl daemon-reload
sudo systemctl restart docker
Copy the code
The end of the
Welcome everyone little attention, little praise!