Docker concept, installation and configuration mirror accelerator

Docker

(Call your own article) If you are unfamiliar with linux, you can take a look at these articles
Linux installation MySQL, JDK (including environment variable configuration), Tomcat
Linux introduction and common operation commands
Use of vi editor in Linux and ps system management commands
img

(1) From the framework of VM and Docker, it is intuitive that VM has an additional layer of Guest OS. At the same time, Hypervisor will virtualize hardware resources, and docker directly uses hardware resources, so the resource utilization rate is lower than that of docker.

(2) openstack can create virtual machines at a speed of 10 units/min, which is weak in front of docker. Because docker uses the system kernel of the host machine, it can create a large number of containers within a few seconds. Their The startup speed is an order of magnitude difference. Each isolation environment of Docker is process-level, each daemon process shares the operating system kernel, and packages the necessary dependencies for running services in the isolation environment. Therefore, each container starts very quickly and occupies very few resources, which is very suitable for deploying background services on the server.

(3) Docker has the characteristics of small size, fast migration and deployment, and efficient operation, but its isolation is worse than server virtualization;

(4) Virtual machines are better at completely isolating the entire operating environment. For example, cloud service providers usually use virtual machine technology to isolate different users. And Docker is usually used to isolate different applications, such as front-end, back-end and database.

The core problem solved by server virtualization is resource allocation, while the core problem solved by containers is application development, testing and deployment.

(5) The VM creates a virtualization layer, a virtualized operating system, and a virtualized warehouse on the basis of the host machine and the host machine's operating system, and then installs the application; the Docker container creates a Docker engine on the host machine's operating system, directly running on the host machine The host operating system invokes hardware resources.

(6) Although a virtual machine can isolate many "sub-computers", it takes up more space and starts slower. Virtual machine software may also cost money, such as VMWare. Container technology does not need to virtualize the entire operating system, but only needs to virtualize a small-scale environment, similar to a "sandbox". As for the running space, a virtual machine generally requires a few GB to tens of GB of space, while a container only needs MB or even KB.

img

(7) The hypervisor of the virtual machine creates a very strong boundary to prevent applications from breaking through it, while the boundary of the container is not so strong.

Getting to know Docker

1.1 docker concept

1. Docker is an open source application container engine
2. Born in early 2013, it is implemented based on the Go language and produced by dotCloud (later renamed as Docker Inc)
3. Docker is a tool that allows developers to package their applications and dependencies into one Lightweight, portable container engine (like a car engine), then publish to any popular Linux box.
4. Containers are fully sandboxed and isolated from each other.
5. Container performance overhead is extremely low.
6. Docker has been divided into CE (Community Edition: Community Edition) and EE (Enterprise Edition: Enterprise Edition) since version 17.03

image-20210310145757133

docker plays the role of the whale in the picture, and the containers above the whale are containers, in which are the applications we develop (not limited to web applications), and each container has its own independent environment (environment settings, network , file system...), without interfering with each other. And each box can be packaged into a new image and run directly in the docker environment of other servers, no need to repeat the installation of the program running environment

1.2 docker application scenarios

Case number one:

A few days ago, a batch of servers in the company was about to expire. Since the servers were purchased in 2015, the performance of the hardware was much lower than that of the new cloud hosts, so it was decided to replace all the servers with new generation servers, but Zhang San was preparing to When I migrated the servers, I felt a sense of collapse in my heart. After careful calculation, each server had to do the same thing.

1、装jdk、Tomcat、nginx
2、配置jdk环境变量和系统变量
3、配置Tomcat
4、配置nginx
5、安装项目所需的视频解码组件
6、导入项目所需的一些特殊字体

Later, I decided to use the docker deployment method. After installing docker on each server, I only need to pull the Tomcat image from the mirror warehouse on one of the servers, set up these configurations, and upload it as my own image. Go to the mirror warehouse, and then download the mirror image you made on several other servers, run it in docker, upload the code, and everything will be fine.

case two

During the Christmas event not long ago, the company’s temporary event plan was finally launched after the programmers worked overtime, but after it was launched, the Chinese name in the promotion poster was found to be garbled. The leader blamed the testers for not doing a good job in the test. Said that I have tested countless times and submitted the test report, and I have solved all the problems before going online; I have no choice but to let the server colleagues check the tomcat configuration in the official server, and found that tomcat used the default encoding method: iso8859-1, and The test environment is UTF-8. In response to this problem, the project team decided to migrate the development environment to docker. After the test in the test environment was correct, the image was packaged and released to the official environment, which solved the problems caused by different environments.

1.3 install docker

Docker can run on MAC, Windows, CentOS, UBUNTU and other operating systems. This course installs Docker based on CentOS 7.
Official website: https://www.docker.com

#yum 包更新到最新
yum update -y

#安装需要的软件包
yum install -y yum-utils device-mapper-persistent-data lvm2

#设置yum源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

# 安装docker
yum install -y docker-ce

#查看docker版本,验证是否验证成功
docker -v

Considering that downloading docker-ce from docker’s official warehouse is sometimes slow, you can use the following command to change the download URL to Huawei’s mirror server:
sudo sed -i 's+download.docker.com+repo.huaweicloud.com/ docker-ce+' /etc/yum.repos.d/docker-ce.repo

[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-kpNpjAmL-1680189146488) (C:\Users\lps\AppData\Roaming\Typora\typora-user-images\ image-20230330203200234.png)]

1.4 docker related concepts

  • Image: A Docker image is equivalent to a root file system. For example, the official image ubuntu:16.04 contains a complete set of root file system of Ubuntu16.04 minimum system.
  • Container: The relationship between image and container is like classes and objects in object-oriented programming. Mirror is a static definition, and container is an entity when mirroring is running. Containers can be created, started, stopped, deleted, paused, etc.
  • Repository: The repository can be regarded as a code control center for storing images.

1.5 Configure Docker image accelerator

By default, the docker image will be downloaded from the docker hub (https://hub.docker.com/) in the future, which is too slow. Generally, mirror accelerators are configured:

  • USTC: USTC Mirror Accelerator (https://docker.mirrors.ustc.edu.cn)
  • Ali Cloud
  • NetEase Cloud
  • Tencent Cloud

Alibaba Cloud Image Accelerator Configuration

First log in to Alibaba Cloud, click on the console, then click on the three-character icon on the left, then click on products and services, search for "mirror" in the keyword input place, and the container mirroring service will be displayed, click on "container mirroring service", There is a mirror center (mirror accelerator) at the bottom of the left, click the mirror accelerator, copy the following code to linux and execute it

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://88y9upwp.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

おすすめ

転載: blog.csdn.net/lps12345666/article/details/129869214