Docker [2] | take you to quickly install docker

Hello, I'm Mr. Jiao ya (o^^o)
After understanding how Docker is different and such a talent, we will explain it step by step from the basis of Docker.

1, Basic composition of Docker

1. Docker server and client

Before explaining the basic composition of Docker, we need to understand that Docker is a client server (C/S) architecture program. I don't understand what is C/S architecture, right? Let me briefly explain here. Generally speaking, application architecture is divided into two types:

Client server (C/S)Browser server (B/S)

Client server (C / s): client server (C / s) = client server. For example: QQ, Xunlei, webcast, etc. In the dead of night, you hide in the quilt and use your installed webcast artifact to see unknown blockbusters. The webcast software needs to communicate with the server, and the server continuously returns all kinds of picture information to the webcast artifact.

This way of data communication with the server by installing software is C/S architecture.

C/S system structure

Browser server (B/S): browser server (B/S) = browser server. For example: all websites are B/S architecture. You can find your friends, take a step to talk, ask for a website, and directly enter the browser to see unknown blockbusters. This way of viewing movies without installing software and directly having a website belongs to B/S architecture.

B/S system structure

Generally speaking, each client of C/S must install and configure special software. The biggest advantage of B/S is that there is no need to install any special software, as long as there is a browser.

Docker engine is an application of c/s structure. The docker client only needs to send a request to the docker server or daemon. The server or daemon completes all work and returns the results. The main components are shown in the figure below:

  • Server is a resident process
  • REST API implements the interaction protocol between client and server
  • CLI realizes the management of containers and images, and provides users with a unified operation interface

2. Basic composition of Docker

From the previous section, we can know that Docker uses C/S architecture. The client communicates with the server process through the interface to realize the construction, operation and publishing of containers. Client and server can run in the same cluster, and can also realize remote communication through cross host.

Image:

Docker image is a read-only template that can be used to create containers. One image can create multiple containers, just like classes and objects in java. Classes are images and containers are objects.

Container:

Docker uses containers to run applications. A container is a running instance created from an image. It can be started, started, stopped and deleted. Each container is an isolated and secure platform.

Repository:

Warehouse is the place where images are stored. It is divided into public warehouse and private warehouse. The official warehouse Docker Hub is foreign, while many domestic companies, such as Alibaba cloud and Huawei cloud, have their own container services. Docker uses foreign warehouses by default, and our access in China is very slow, Therefore, we need to configure image acceleration when learning.

The above introduction, I think, may be a bit harsh for the old fellow who has just studied Docker. I was just learning Docker. But it doesn't matter. Let me give a popular example:

We should note that Docker itself is not a container. It is just a tool for creating containers. It is an application container engine.

To understand Docker, you only need to know two points:

First, Build, Ship and Run

Build (build image): the image is like a container, including files, running environment and other resources.
Ship (transport image): transport between the host and the warehouse. The warehouse here is like a super wharf.
Run image: the running image is a container, which is the place where the program runs.

for instance:
My father is old and wants to go back to his hometown to build A house. We came to his hometown and found A busy place at ordinary times. We bought A foundation to build A house, so my father and I moved cement, stones and all kinds of materials. It took nine cattle and two tigers to build the house at last. As A result, after living for some time, my father said it was too noisy here and wanted to change to A quiet place. According to the traditional method, we can only move stones, cut wood, draw drawings and build houses again. However, Doraemon took out A magic wand from the treasure bag, which can pack the house built by me and my father into A "mirror image" and put it in my backpack.

When I get to a quiet place and find an open space, I will use this "mirror image" to copy a house, put it there and check in with my bag. So the second point of Docker is: build once, run anywhere.

From the above example, the image placed in my bag is the Docker image, while the house I copied with a magic wand in a quiet space is a Docker container, and my backpack is the Docker warehouse.

Since the house built by my father and I can be packaged into a mirror image, other people's houses can also be made into a mirror image. In this way, can we live in all kinds of luxury houses directly. The mirror images made of so many houses need a big bag to install. Therefore, this big bag has become a repository in professional terms. Therefore, the official provides a Docker Hub for everyone to share the house image. Of course, you can also build a private warehouse, dullele, and don't share your own house image to others.

2, Online installation of Docker

Docker is officially recommended to be installed in Ubuntu, because docker is released based on Unbantu, and generally, Ubuntu is the first to update or patch the problems of docker. In many versions of Centos, it is not supported to update some of the latest patches.

Since our learning environment uses Centos, we install Docker on Centos here.
be careful:

  • Linux requires kernel 3.0 or above
  • CentOS needs to be version 7

Since there are official tips, how can we view the system kernel?

1. Verify with the uname command

[root@localhost docker]# uname -r
3.10.0-1127.el7.x86_64

2. Uninstall installed Docker

If Docker has been installed, please uninstall it first and then reinstall it to ensure that the overall environment is consistent.

yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine

3. Install yum toolkit and storage driver

yum install -y yum-utils

4. Set the warehouse of the image

yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
#The above methods are from abroad by default and are not recommended

#It is recommended to use the domestic Alibaba cloud docker image
yum-config-manager \
    --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

5. Install docker

Note: docker CE is the community version and ee is the enterprise version. Here we can use the community version.

yum install docker-ce docker-ce-cli containerd.io

6. Start docker

systemctl start docker

7. Set startup

systemctl enable docker

8. Check Docker version after installation

[root@localhost docker]# docker version
Client: Docker Engine - Community
 Version:           19.03.13
 API version:       1.40
 Go version:        go1.13.15
 Git commit:        4484c46d9d
 Built:             Wed Sep 16 17:03:45 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.13
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       4484c46d9d
  Built:            Wed Sep 16 17:02:21 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.3.7
  GitCommit:        8fba4e9a7d01810a393d5d25a3621dc101981175
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

9. Configuring alicloud image acceleration

In view of the domestic network problems, it is very slow to pull the Docker image later. We can configure the accelerator to solve this problem.
Log in to alicloud
Search container mirroring service

Get accelerator address

By modifying the daemon configuration file / etc / docker / daemon JSON to use the accelerator

tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://pak31uuv.mirror.aliyuncs.com"]
}
EOF

# Restart Docker
systemctl daemon-reload
systemctl restart docker

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

10. Verify that the configuration is successful

docker info

# The output is as follows
Client:
 Debug Mode: false

Server:
 Containers: 15
  Running: 12
  Paused: 0
  Stopped: 3
 Images: 24
 Server Version: 19.03.6
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: systemd
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 
 runc version: 
 init version: 
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 4.15.0-96-generic
 Operating System: Ubuntu 18.04.4 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 7.767GiB
 Name: docker-services
 ID: YZSB:WJFB:RS4K:V22L:IVGK:GZVZ:UQL4:MCCR:MQ4X:6HRE:T5RM:53M5
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:
  https://k7da99jp.mirror.aliyuncs.com/
  https://dockerhub.azk8s.cn/
  https://registry.docker-cn.com/
 Live Restore Enabled: false

WARNING: No swap limit support

3, Offline installation of Docker Intranet Environment

In many cases, the virtual machine or server that needs to install docker cannot access the Internet, so docker needs to be installed offline.

preparation

A virtual machine or server that can access the Internet. The operating system is unlimited. The modified machine can access the machine where docker is to be installed

STEP 1: the following operations are performed on a machine that can access the Internet
Download installation package access https://download.docker.com/linux/static/stable/ Select the appropriate version and download it. The author uses: https://download.docker.com/linux/static/stable/x86_64/docker-18.09.6.tgz

STEP 2: upload the downloaded installation package to the machine to be installed
STEP 3: the following operations are performed on the machine to be installed
1. Unzip the installation package

tar -zxvf docker-18.09.6.tgz 

2. Copy the extracted files to the specified folder

 cp docker/* /usr/bin/ 

3. Register and edit docker service

vim /etc/systemd/system/docker.service

4. Copy the following into this document

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
  
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
  
[Install]
WantedBy=multi-user.target

5. Start after adding permissions

chmod +x /etc/systemd/system/docker.service

6. Reload profile

systemctl daemon-reload 

7. Start Docker

systemctl start docker

8. Set startup and self startup

systemctl enable docker.service

9. Verify that the installation was successful

systemctl status docker
docker -v

4, Run the first container

Let's take Nginx as an example to experience how Docker runs containers

# Download Image
docker pull nginx

# Run container
docker run --name nginx-container -p 80:80 -d nginx

The browser can access Nginx by entering the virtual machine address

📢 Blog home page: https://blog.csdn.net/shujuelin
📢 Welcome to like 👍 Collection ⭐ Leaving a message. 📝 Please correct any mistakes!

Keywords: Operation & Maintenance Docker server

Added by Swerve1000 on Thu, 24 Feb 2022 03:45:23 +0200