Docker architecture and installation

Articles and codes have been archived in [Github warehouse: https://github.com/timerring/backend-tutorial ] or the public account [AIShareLab] can also be obtained by replying to docker .

foreword

CentOS Docker installation

Docker is not a general purpose container tool , it relies on an existing and running Linux kernel environment.

Docker essentially creates an isolated file environment under the already running Linux, so its execution efficiency is almost equal to that of the deployed Linux host. Therefore, Docker must be deployed on a system with a Linux kernel . If other systems want to deploy Docker, they must install a virtual Linux environment.

prerequisite

Currently, only the kernel in the CentOS distribution supports Docker. Docker runs on CentOS 7 (64-bit), requires the system to be 64-bit, and the kernel version of the Linux system to be 3.8 or above. Centos7.X is selected here

View your own kernel
unamecommand is used to print current system-related information (kernel version number, hardware architecture, host name and operating system type, etc.).
For example: uname -rorcat /etc/redhat-release

Basic components of Docker

mirror image

A Docker image (Image) is a read-only template. Images can be used to create Docker containers, and one image can create many containers.

It is also equivalent to a root file system. For example, the official image centos: 7 contains a complete root file system of the centos: 7 minimal system.

Equivalent to the "source code" of the container, the docker image file is similar to the Java class template, and the docker container instance is similar to the new instance object in java.

container

1 From an object-oriented perspective

Docker uses a container (Container) to run one or a group of applications independently. The application or service runs in the container. The container is similar to a virtualized running environment. The container is a running instance created with a mirror . Just like classes and instance objects in Java, images are static definitions, and containers are entities when images are running. Containers provide a standard and isolated operating environment for images, which can be started, started, stopped, and deleted. Each container is an isolated and secure platform

2 From the perspective of mirror container

The container can be regarded as a simple version of the Linux environment (including root user authority, process space, user space and network space, etc.) and the applications running in it.

warehouse

The warehouse (Repository) is a place where image files are stored centrally.

Similar to Maven warehouse, where various jar packages are stored; github warehouse, where various git projects are stored.

The official registry provided by Docker is called Docker Hub, where various image templates are stored. Warehouses are divided into public warehouses (Public) and private warehouses (Private).

The largest public repository is Docker Hub ( https://hub.docker.com/ ), which stores a large number of images for users to download. Domestic public warehouses include Alibaba Cloud, NetEase Cloud, etc.

small summary

Docker itself is a container running carrier or management engine. We package the application program and configuration dependencies to form a deliverable operating environment. This packaged operating 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).

Image files can be thought of as templates for containers. Docker generates instances of containers based on image files. The same image file can generate multiple container instances running at the same time.

Image file: The container instance generated by the image file is itself a file called an image file.

Container instance: A container runs a service. When we need it, we can create a corresponding running instance through the docker client, which is our container

Warehouse: It is a place to put a bunch of images. We can publish the images to the warehouse, and then pull them down from the warehouse when needed.

Docker platform architecture diagram

Overview of how it works:

Docker is a system of Client-Server structure. The Docker daemon runs on the host and is accessed from the client through a Socket connection. The daemon accepts commands from the client and manages the containers running on the host. A container is a runtime environment, which is the container we mentioned earlier. (the process is similar to mysql)

Docker is a C/S model architecture, the backend is a loosely coupled architecture, and many modules perform their duties.

The basic process of Docker operation is:

  1. Users use Docker Client to establish communication with Docker Daemon and send requests to the latter.
  2. As the main part of the Docker architecture, Docker Daemon first provides the function of Docker Server so that it can accept requests from Docker Client.
  3. Docker Engine executes a series of jobs inside Docker, and each job exists in the form of a Job.
  4. During the running of the job, when the container image is needed, the image is downloaded from the Docker Registy, and the downloaded image is stored in the form of Graph through the image management driver Graph drver.
  5. When it is necessary to create a network environment for Docker, create and configure the Docker container network environment through the network management driver Network driver.
  6. When it is necessary to limit the running resources of the Docker container or perform operations such as user instructions, it is done through the Exec driver.
  7. Libcontainer is an independent container management package. Both Network driver and Exec driver implement specific operations on containers through Libcontainer.

Install Docker

Documentation: https://docs.docker.com/engine/install/centos/

  1. Make sure you are CentOS 7 and abovecat /etc/redhat-release
  2. Uninstall old versions https://docs.docker.com/engine/install/centos/#uninstall-old-versions
  3. Yum installs gcc related yum -y install gcc,yum -y install gcc-c++
  4. Install yum-utilsthe package `yum install -y yum-utils
  5. Set up a stable mirror warehouse (recommended Alibaba Cloud)
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  1. Update yum package index `yum makecache fast
  2. Install docker-engine
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  1. Start docker `systemctl start docker
  2. test docker versionand `docker run hello-world
  3. Uninstall: https://docs.docker.com/engine/install/centos/#uninstall-docker-engine

Alibaba Cloud Mirror Acceleration

https://promotion.aliyun.com/ntms/act/kubernetes.html

Obtain the accelerator address connection: log in to the Alibaba Cloud developer platform, click on the console, select the container image service, and obtain the accelerator address. Paste the script under the page and execute it directly.

Or write it in steps:
mkdir -p /etc/dockerandvim /etc/docker/daemon.json

Then restart the service:

systemctl daemon-reload
systemctl restart docker

Why Docker is faster than VM

  1. Docker has fewer abstraction layers than virtual machines
    Since docker does not require a Hypervisor (virtual machine) to virtualize hardware resources, programs running on docker containers directly use the hardware resources of the actual physical machine . Therefore, docker will have obvious advantages in efficiency in terms of CPU and memory utilization.

  2. Docker uses the kernel of the host machine without loading the operating system OS kernel.
    When creating a new container, docker does not need to reload an operating system kernel like a virtual machine. In order to avoid the time-consuming and resource-consuming process of booting, loading the operating system kernel and returning, when creating a new virtual machine, the virtual machine software needs to load the OS, and the process of returning to the new creation is at the level of minutes. However, docker omits the return process because it directly uses the host's operating system, so it only takes a few seconds to create a new docker container.

Guess you like

Origin blog.csdn.net/m0_52316372/article/details/131899091