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.


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.


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.


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

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 \
#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 \

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

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
  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
  Version:          1.3.7
  GitCommit:        8fba4e9a7d01810a393d5d25a3621dc101981175
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
  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": [""]

# 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):

10. Verify that the configuration is successful

docker info

# The output is as follows
 Debug Mode: false

 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
  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:
   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
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
 Registry Mirrors:
 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.


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 Select the appropriate version and download it. The author uses:

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

Description=Docker Application Container Engine
Documentation= firewalld.service
# 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
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.
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
# set delegate yes so that systemd does not reset the cgroups of docker containers
# kill only the docker process, not all processes in the cgroup
# restart the docker process if it exits prematurely

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:
📢 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