Docker II installation

Posted by harmclan on Wed, 06 Oct 2021 15:58:18 +0200

2. Docker installation

https://www.jianshu.com/p/2e91d1272154

2.1 premise description

CentOS Docker installation

Docker supports the following CentOS versions:

CentOS 7 (64-bit)

CentOS 6.5 (64 bit) or later

prerequisite

Currently, only the kernel in the distribution version of CentOS supports Docker.

Docker runs on CentOS 7. The system is required to be 64 bit and the system kernel version is above 3.10.

Docker runs on CentOS with CentOS-6.5 or higher. The system is required to be 64 bit and the system kernel version is 2.6.32-431 or higher.

View your own kernel

The uname command is used to print information about the current system (kernel version number, hardware architecture, host name, operating system type, etc.).

uname -r

View the installed CentOS version information (yes for CentOS6.8, but not for CentOS7)

lsb_release -a
cat /etc/redhat-release

2.2 basic composition of docker

2.2.1 image

Docker Image is a read-only template. Images can be used to create docker containers. One Image can create many containers.

The relationship between container and image is similar to that of objects and classes in object-oriented programming.

2.2.2 container

Docker uses a Container to run one or a group of applications independently. Containers are running instances created with images.

It can be started, started, stopped and deleted. Each container is an isolated and secure platform.

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

The definition and mirror as like as two peas are identical, and the same is the same view of a stack. The only difference is that the top layer of the container is readable and writable.

2.2.3 repository

A Repository is a place where image files are stored centrally.

There is a difference between a repository and a repository Registry. Multiple warehouses are often stored on the warehouse registration server. Each warehouse contains multiple images, and each image has a different tag.

Warehouses are divided into Public warehouses and Private warehouses.

The largest public warehouse is docker hub( https://hub.docker.com/ ), a large number of images are stored for users to download. Domestic public warehouses include Alibaba cloud, Netease cloud, etc

2.2.4 summary

It is necessary to correctly understand the concepts of warehousing / image / container:

Docker itself is a container running carrier or management engine. We package the application and configuration dependencies to form a deliverable running environment, which looks like an image image file. Only through this image file can docker containers be generated. Image files can be regarded as templates for containers. Docker generates an instance of the container based on the image file. The same image file can generate multiple container instances running at the same time.

  • The container instance generated by the image file is also a file, which is called an image file.
  • A container runs a service. When we need it, we can create a corresponding running instance through the docker client, that is, our container
  • As for storage, it is a place where a pile of images are placed. We can publish the images to the storage and pull them down from the storage when necessary.

1541678720780.png

2.3 installation steps

2.3.1 installing Docker in centos6.8

yum install -y epel-release

Docker is published using EPEL. The OS of RHEL system must first ensure that it has an EPEL warehouse. Otherwise, check the OS version first, and then install the corresponding EPEL package.

yum install -y docker-io
#Configuration file after installation: / etc/sysconfig/docker
ls -l docker*
cat /etc/sysconfig/docker
#Start Docker background service:
service docker start
#docker version Verification
docker version

2.3.2 installing Docker in centos7

https://docs.docker.com/install/linux/docker-ce/centos/

Installation steps

Chinese installation reference manual on the official website

https://docs.docker-cn.com/engine/installation/linux/docker-ce/centos/#prerequisites

#Make sure you are CentOS 7 or above
cat /etc/redhat-release
#Install gcc related using yum or up2date. CentOS7 can access the Internet
yum -y install gcc
yum -y install gcc-c++
#Uninstall old version
yum -y remove docker docker-common docker-selinux docker-engine
#2018.3 official website version
yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine
#Install required packages
yum install -y yum-utils device-mapper-persistent-data lvm2

#Set stable image warehouse
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
 report errors:
1   [Errno 14] curl#35 - TCP connection reset by peer
2   [Errno 12] curl#35 - Timeout
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#Update yum package index
yum makecache fast
#Installing DOCKER CE
yum -y install docker-ce
#Start docker
systemctl start docker
#test
docker version
docker run hello-world
#Configure mirror acceleration
mkdir -p /etc/docker
vim  /etc/docker/daemon.json ==Will report an error,hold daemon.json Change to daemon.conf

#Netease cloud
{"registry-mirrors": ["http://hub-mirror.c.163.com"] }
#Alibaba cloud
{"registry-mirrors": ["https://{own code}. mirror.aliyuncs.com "]}

systemctl daemon-reload
systemctl restart docker
#uninstall
systemctl stop docker
yum -y remove docker-ce
rm -rf /var/lib/docker

Own Ali image
https://gyfic2tp.mirror.aliyuncs.com
{"registry-mirrors": ["https://gyfic2tp.mirror.aliyuncs.com"]}

2.4 forever HelloWorld

2.4.1 Alibaba cloud image acceleration

What is it?

https://dev.aliyun.com/search.html

Register your own alicloud account (reusable Taobao account)

Get accelerator address connection

Log in to alicloud Developer Platform

Get accelerator address

Configure native Docker to run image accelerator

In view of the domestic network problems, it is very slow to pull the Docker image later. We need to configure an accelerator to solve it,

I use the image address of Alibaba cloud's own account (you need to register one of your own): https://xxxx.mirror.aliyuncs.com

vim /etc/sysconfig/docker
#Configure the Alibaba cloud acceleration address under your account
other_args="--registry-mirror=https://Your own account acceleration information.mirror.aliyuncs.com“
#Restart Docker background service:
service docker restart
#After configuring the accelerator under Linux system, you need to check whether it takes effect
#If you see the configured -- registry mirror parameter from the result, the configuration is successful, as shown below:
ps -ef|grep docker

2.4.2 Netease cloud acceleration

Basically the same as Alibaba cloud

The configuration of Json string is different:

cat /etc/docker/daemon.json
{    "registry-mirrors":   ["http://hub-mirror.c.163.com"]   }

2.4.3 start Docker background container (test run Hello World)

docker run hello-world

After outputting this prompt, hello world will stop running and the container will terminate automatically.

What did run do

clip_image059.jpg

2.5 bottom layer principle

2.5.1 how docker works

Docker is a client server system. The docker daemon runs on the host and then accesses from the client through a Socket connection. The daemon receives commands from the client and manages containers running on the host. Container is a runtime environment, which is the container we mentioned earlier.

clip_image061.jpg

2.5.2 why is Docker faster than VM

  • Docker has fewer abstraction layers than virtual machines. The Hypervisor is not required by docker to realize hardware resource virtualization. The programs running on the docker container directly use the hardware resources of the actual physical machine. Therefore, docker will have obvious advantages in CPU and memory utilization.

  • Docker uses the kernel of the host computer instead of the Guest OS. Therefore, when creating a new container, docker does not need to reload an operating system kernel like the virtual machine. The process of searching and loading the operating system kernel is still avoided. When creating a new virtual machine, the virtual machine software needs to load the Guest OS, and the process is at the minute level. Because docker directly uses the operating system of the host, the return process is omitted. Therefore, it only takes a few seconds to create a docker container.

    Docker containerVirtual machine (VM)
    operating systemShare OS with dormitory hostVirtual machine OS running on host OS
    Storage sizeSmall image for easy storage and transmissionImage size (vmdk, vdi, etc.)
    Operational performanceAlmost no additional performance lossAdditional CPU and memory consumption of operating system
    TransplantabilityLightweight and flexible, suitable for LinuxBulky and highly coupled with virtualization technology
    Hardware affinityFor software developersFor hardware operators
    Deployment speedFast, second levelSlow, minute scale

Topics: Linux CentOS Docker