How to install docker on centos7

What is Docker?

Docker is an open source application container engine that allows developers to package their applications and dependencies into a portable container, and then publish it to any popular Linux or Windows operating system machine. Virtualization, container It is completely using the sandbox mechanism, and there will be no interface between them.

A complete Docker consists of the following parts:

  1. DockerClient client
  2. Docker Daemon daemon process
  3. Docker Image mirroring
  4. DockerContainer container

How Docker works

The problem solved by the Docker core is to use LXC to implement functions similar to VM, so as to provide users with more computing resources by using more economical hardware resources. Different from the way of VM, LXC is not a set of hardware virtualization method - it cannot be attributed to any one of full virtualization, partial virtualization and paravirtualization, but an operating system level virtualization method, which may not be understood Not as intuitive as VM. So let's start from the problems that docker needs to solve from virtualization to see how he meets the virtualization needs of users.

Users need to consider the virtualization method, especially the hardware virtualization method, which mainly needs to solve the following four problems:

  1. Isolation - Each user instance is isolated from each other and does not affect each other. The method given by the hardware virtualization method is VM, the method given by LXC is container, and the more detailed one is kernel namespace
  2. Quotaable/Measurable - Each user instance can provide its computing resources on demand, and the resources used can be metered. The hardware virtualization method can be easily implemented because the CPU is virtualized, and the memory can be easily implemented. LXC mainly uses cgroups to control resources
  3. Mobility - User instances can be easily copied, moved and recreated. The hardware virtualization method provides snapshot and image to realize, and docker (mainly) uses AUFS to realize
  4. Security - This topic is relatively large, and the emphasis here is to protect the container as much as possible from the perspective of the host. Hardware virtualization method Because the level of virtualization is relatively high, user processes are translated and run in virtual machine containers such as KVM. However, for LXC, user processes are child processes of the lxc-start process, but in the namespace of the Kernel Isolated, so some kernel patches are needed to ensure that the user's operating environment is not subject to malicious intrusion from the host, dotcloud (mainly) uses the kernel grsec patch to solve it.

Advantages and disadvantages of Docker

advantage

Due to its lightweight virtualization based on LXC, the most obvious feature of docker compared to KVM is that it starts quickly and occupies less resources. Therefore, for building an isolated and standardized operating environment, lightweight PaaS (such as dokku), building automated testing and continuous integration environments, and all applications that can be scaled out (especially web applications that need to be quickly started and stopped to deal with peaks and valleys) .

  1. To build a standardized operating environment, most of the existing solutions are to run a set of puppet/chef or an image file on a baseOS. The disadvantage is that the former requires many prerequisites for the base OS, and the latter can hardly be modified (because copy on write The file format of rootfs is read only at runtime). And the latter file size is large, environment management and version control itself is also a problem.
  2. The PaaS environment is self-evident, and its design and the case of dotcloud are all based on the environment of PaaS products
  3. Because of its standardized build method (buildfile) and good REST API, automated testing and continuous integration/deployment can be well integrated
  4. Because of the lightweight characteristics of LXC, it starts quickly, and docker can only load the changed part of each container, so that the resource occupation is small, and it can be faster and occupy less in a stand-alone environment than virtualization solutions such as KVM. less resources

shortcoming

Docker is not omnipotent, nor is it a substitute for virtualization methods such as KVM at the beginning of its design. A few points are briefly summarized:

  1. Docker is based on Linux 64bit and cannot be used in 32bit linux/Windows/unix environment
  2. LXC is based on linux kernel functions such as cgroup, so the guest system of the container can only be linux base
  3. Compared with virtualization solutions such as KVM, the isolation is still somewhat lacking, and all containers share a part of the runtime library
  4. Network management is relatively simple, mainly based on namespace isolation
  5. Compared with virtualization solutions such as KVM, the cpu of cgroup and the cpu function provided by cpuset are difficult to measure (so dotcloud is mainly charged by memory)
  6. Docker has limited management of disk
  7. The container is destroyed as the user process stops, and user data such as logs in the container are inconvenient to collect

For 1-2, those with windows base application requirements can basically pass; 3-5 mainly depends on the user's needs, whether a container or a VM is needed, and it also determines that docker is not feasible as an IaaS.

For 6 and 7, although it is a function that docker itself does not support, it can be solved by other means (disk quota, mount --bind). In short, the choice of container or vm is a trade-off between isolation and resource reusability.

Docker is not suitable for all application scenarios, Docker can only virtualize Linux-based services. Windows Azure Services can run Docker instances, but so far Windows Services cannot be virtualized.

Probably the biggest hurdle is managing the interactions between instances. Since all application components are separated into different containers, all servers need to communicate with each other in a consistent manner. This means that anyone choosing complex infrastructure must master application programming interface management and cluster tools such as Swarm, Mesos or Kubernetes to ensure that machines perform as expected and support failover.

Docker is essentially an add-on system. It is possible to build an application using different layers of the file system. Each component is added on top of the ones already created before, which can be more sensible than being a file system. The layered architecture brings another efficiency improvement. When you rebuild a changed Docker image, you don't need to rebuild the entire Docker image, but only the changed part.

Start installing docker on centos7 system

Refer to the official website installation and uninstallation documentation: https://docs.docker.com/engine/install/centos/

ready

  1. Determine the Linux system version, centos7 and above
cat /etc/redhat-release
  1. First uninstall the old version of docker. Skip this step if the new system is not installed. You can refer to the installation documentation on the official website to introduce uninstall
sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
  1. Install gcc, gcc-c++
sudo yum install gcc
sudo yum install gcc-c++
  1. Install the required package yum-utils, and install it in a stable way that many people use for safety
sudo yum install -y yum-utils
  1. Setting up the docker remote warehouse
    The official remote warehouse is not recommended, because the foreign address is generally very slow and needs to go over the wall
sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

Recommended method: Set the address of the domestic Alibaba Cloud warehouse

sudo yum-config-manager \
    --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  1. Update yum package index
sudo yum makecache fast
  1. After the preparations are complete, start the official installation of docker-ce
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  1. start docker
sudo systemctl start docker
  1. Check the docker process to confirm whether the startup is successful
ps -ef | grep docker
  1. View installed docker version
docker version
  1. Run the hello world image test
sudo docker run hello-world

Guess you like

Origin blog.csdn.net/lu962820662/article/details/129335339