第一步确认系统环境
系统内核版本确定
[root@tiangong ~]# uname -r
3.10.0-514.26.2.el7.x86_64
系统版本确定
[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/"
第二部通过docker官网安装
打开docker官网 https://www.docker.com/
docker官网
docker官网
docker官网
docker官网
按照文档开始安装
#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
#我们可以将地址换成国内镜像,速度更快
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
(我们在更新yum源或者出现配置yum源之后,通常都会使用yum makecache 生成缓存)
#4.2 安装docker引擎
yum install docker-ce docker-ce-cli containerd.io
image.png
启动并测试安装是否成功
[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
测试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/
配置阿里云镜像加速
首先打开阿里云控制台,然后打开容器镜像加速服务
image.png
image.png
检测是否加速成功
$ docker info
Registry Mirrors:
https://reg-mirror.qiniu.com
#在ssh工具中执行以下四条命令即可使用阿里云镜像加速服务
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命令执行流程(转载)
run命令执行流程图
docker原理(转载)
docker原理图