第一步確認(rèn)系統(tǒng)環(huán)境
系統(tǒng)內(nèi)核版本確定
[root@tiangong ~]# uname -r
3.10.0-514.26.2.el7.x86_64
系統(tǒng)版本確定
[root@tiangong /]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
第二部通過(guò)docker官網(wǎng)安裝
打開(kāi)docker官網(wǎng) https://www.docker.com/

docker官網(wǎng)

docker官網(wǎng)

docker官網(wǎng)

docker官網(wǎng)
按照文檔開(kāi)始安裝
#1 卸載舊版本命令
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
[root@tiangong /]# yum remove docker \
> docker-client \
> docker-client-latest \
> docker-common \
> docker-latest \
> docker-latest-logrotate \
> docker-logrotate \
> docker-engine
Loaded plugins: fastestmirror
No Match for argument: docker
No Match for argument: docker-client
No Match for argument: docker-client-latest
No Match for argument: docker-common
No Match for argument: docker-latest
No Match for argument: docker-latest-logrotate
No Match for argument: docker-logrotate
No Match for argument: docker-engine
No Packages marked for removal
#2 下載所需要的安裝包
yum install -y yum-utils
[root@tiangong /]# yum install -y yum-utils
Loaded plugins: fastestmirror
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/3): epel/x86_64/updateinfo | 1.0 MB 00:00:00
(2/3): updates/7/x86_64/primary_db | 3.0 MB 00:00:00
(3/3): epel/x86_64/primary_db | 6.8 MB 00:00:00
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package yum-utils.noarch 0:1.1.31-54.el7_8 will be installed
--> Processing Dependency: python-kitchen for package: yum-utils-1.1.31-54.el7_8.noarch
--> Running transaction check
---> Package python-kitchen.noarch 0:1.1.1-5.el7 will be installed
--> Processing Dependency: python-chardet for package: python-kitchen-1.1.1-5.el7.noarch
--> Running transaction check
---> Package python-chardet.noarch 0:2.2.1-3.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================
Package Arch Version Repository Size
=====================================================================================
Installing:
yum-utils noarch 1.1.31-54.el7_8 updates 122 k
Installing for dependencies:
python-chardet noarch 2.2.1-3.el7 base 227 k
python-kitchen noarch 1.1.1-5.el7 base 267 k
Transaction Summary
=====================================================================================
Install 1 Package (+2 Dependent packages)
Total download size: 616 k
Installed size: 2.8 M
Downloading packages:
(1/3): yum-utils-1.1.31-54.el7_8.noarch.rpm | 122 kB 00:00:00
(2/3): python-chardet-2.2.1-3.el7.noarch.rpm | 227 kB 00:00:00
(3/3): python-kitchen-1.1.1-5.el7.noarch.rpm | 267 kB 00:00:00
-------------------------------------------------------------------------------------
Total 2.6 MB/s | 616 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : python-chardet-2.2.1-3.el7.noarch 1/3
Installing : python-kitchen-1.1.1-5.el7.noarch 2/3
Installing : yum-utils-1.1.31-54.el7_8.noarch 3/3
Verifying : python-kitchen-1.1.1-5.el7.noarch 1/3
Verifying : yum-utils-1.1.31-54.el7_8.noarch 2/3
Verifying : python-chardet-2.2.1-3.el7.noarch 3/3
Installed:
yum-utils.noarch 0:1.1.31-54.el7_8
Dependency Installed:
python-chardet.noarch 0:2.2.1-3.el7 python-kitchen.noarch 0:1.1.1-5.el7
Complete!
#3 下載鏡像
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
#我們可以將地址換成國(guó)內(nèi)鏡像,速度更快
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@tiangong /]# yum-config-manager \
> --add-repo \
>
.autorelabel etc/ lost+found/ patch/ sbin/ usr/
bin/ home/ media/ proc/ srv/ var/
boot/ lib/ mnt/ root/ sys/ www/
dev/ lib64/ opt/ run/ tmp/
> http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@tiangong /]#
#4.1 更新yum索引
yum makecache fast
(我們?cè)诟聐um源或者出現(xiàn)配置yum源之后,通常都會(huì)使用yum makecache 生成緩存)
#4.2 安裝docker引擎
yum install docker-ce docker-ce-cli containerd.io

image.png
啟動(dòng)并測(cè)試安裝是否成功
[root@tiangong /]# systemctl start docker
[root@tiangong /]# docker version
Client: Docker Engine - Community
Version: 19.03.12
API version: 1.40
Go version: go1.13.10
Git commit: 48a66213fe
Built: Mon Jun 22 15:46:54 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.12
API version: 1.40 (minimum version 1.12)
Go version: go1.13.10
Git commit: 48a66213fe
Built: Mon Jun 22 15:45:28 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
測(cè)試hello world
[root@tiangong /]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:d58e752213a51785838f9eed2b7a498ffa1cb3aa7f946dda11af39286c3db9a9
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
配置阿里云鏡像加速
首先打開(kāi)阿里云控制臺(tái),然后打開(kāi)容器鏡像加速服務(wù)

image.png

image.png
檢測(cè)是否加速成功
$ docker info
Registry Mirrors:
https://reg-mirror.qiniu.com
#在ssh工具中執(zhí)行以下四條命令即可使用阿里云鏡像加速服務(wù)
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://p03g8a8f.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
run命令執(zhí)行流程(轉(zhuǎn)載)

run命令執(zhí)行流程圖
docker原理(轉(zhuǎn)載)

docker原理圖