查看centos内核版本
[root@VM-24-14-centos ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
CentOS 7 (使用yum进行安装)
# step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3: 更新并安装 Docker-CE
sudo yum makecache fast
sudo yum -y install docker-ce
# Step 4: 开启Docker服务
sudo service docker start
注意:其他注意事项在下面的注释中
# 官方软件源默认启用了最新的软件,您可以通过编辑软件源的方式获取各个版本的软件包。例如官方并没有将测试版本的软件源置为可用,你可以通过以下方式开启。同理可以开启各种测试版本等。
# vim /etc/yum.repos.d/docker-ce.repo
# 将 [docker-ce-test] 下方的 enabled=0 修改为 enabled=1
#
# 安装指定版本的Docker-CE:
# Step 1: 查找Docker-CE的版本:
# yum list docker-ce.x86_64 --showduplicates | sort -r
# Loading mirror speeds from cached hostfile
# Loaded plugins: branch, fastestmirror, langpacks
# docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
# docker-ce.x86_64 17.03.1.ce-1.el7.centos @docker-ce-stable
# docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
# Available Packages
# Step2 : 安装指定版本的Docker-CE: (VERSION 例如上面的 17.03.0.ce.1-1.el7.centos)
# sudo yum -y install docker-ce-[VERSION]
# 注意:在某些版本之后,docker-ce安装出现了其他依赖包,如果安装失败的话请关注错误信息。例如 docker-ce 17.03 之后,需要先安装 docker-ce-selinux。
# yum list docker-ce-selinux- --showduplicates | sort -r
# sudo yum -y install docker-ce-selinux-[VERSION]
# 通过经典网络、VPC网络内网安装时,用以下命令替换Step 2中的命令
# 经典网络:
# sudo yum-config-manager --add-repo http://mirrors.aliyuncs.com/docker-ce/linux/centos/docker-ce.repo
# VPC网络:
# sudo yum-config-manager --add-repo http://mirrors.could.aliyuncs.com/docker-ce/linux/centos/docker-ce.repo
版本安装校验: docker version
[root@VM-24-14-centos ~]# docker version
Client: Docker Engine - Community #客户端的版本
Version: 20.10.11
API version: 1.41
Go version: go1.16.9
Git commit: dea9396
Built: Thu Nov 18 00:38:53 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community #服务端的版本
Engine:
Version: 20.10.11
API version: 1.41 (minimum version 1.12)
Go version: go1.16.9
Git commit: 847da18
Built: Thu Nov 18 00:37:17 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.12
GitCommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc:
Version: 1.0.2
GitCommit: v1.0.2-0-g52b36a2
docker-init:
Version: 0.19.0
GitCommit: de40ad0
查看网络信息: ip addr
[root@VM-24-14-centos ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 52:54:00:0f:a8:71 brd ff:ff:ff:ff:ff:ff
inet 10.0.24.14/22 brd 10.0.27.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fe0f:a871/64 scope link
valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default #docker0 虚拟网桥
link/ether 02:42:ec:fc:73:db brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
设置开启启动
查看是否加入开机启动项 systemctl list-unit-files |grep xxx
[root@VM-24-14-centos ~]# systemctl list-unit-files |grep docker
docker.service disabled
docker.socket disabled
[root@VM-24-14-centos ~]# systemctl enable docker.service #设置为自启动服务
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@VM-24-14-centos ~]# systemctl status docker #查看状态
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2021-11-22 11:19:19 CST; 9min ago
Docs: https://docs.docker.com
Main PID: 14752 (dockerd)
CGroup: /system.slice/docker.service
└─14752 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Nov 22 11:19:19 VM-24-14-centos dockerd[14752]: time="2021-11-22T11:19:19.062613511+08:00" level=info msg="scheme \"unix\...e=grpc
Nov 22 11:19:19 VM-24-14-centos dockerd[14752]: time="2021-11-22T11:19:19.062630573+08:00" level=info msg="ccResolverWrap...e=grpc
Nov 22 11:19:19 VM-24-14-centos dockerd[14752]: time="2021-11-22T11:19:19.062640973+08:00" level=info msg="ClientConn swi...e=grpc
Nov 22 11:19:19 VM-24-14-centos dockerd[14752]: time="2021-11-22T11:19:19.112754837+08:00" level=info msg="Loading contai...tart."
Nov 22 11:19:19 VM-24-14-centos dockerd[14752]: time="2021-11-22T11:19:19.210498195+08:00" level=info msg="Default bridge...dress"
Nov 22 11:19:19 VM-24-14-centos dockerd[14752]: time="2021-11-22T11:19:19.246340397+08:00" level=info msg="Loading contai...done."
Nov 22 11:19:19 VM-24-14-centos dockerd[14752]: time="2021-11-22T11:19:19.272172619+08:00" level=info msg="Docker daemon"....10.11
Nov 22 11:19:19 VM-24-14-centos dockerd[14752]: time="2021-11-22T11:19:19.272271775+08:00" level=info msg="Daemon has com...ation"
Nov 22 11:19:19 VM-24-14-centos systemd[1]: Started Docker Application Container Engine.
Nov 22 11:19:19 VM-24-14-centos dockerd[14752]: time="2021-11-22T11:19:19.298526658+08:00" level=info msg="API listen on ....sock"
Hint: Some lines were ellipsized, use -l to show in full.
测试运行: docker run hello-world
[root@VM-24-14-centos ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685
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/
配置加速镜像
1. 安装/升级Docker客户端
推荐安装1.10.0以上版本的Docker客户端,参考文档docker-ce
2. 配置镜像加速器
针对Docker客户端版本大于 1.10.0 的用户
您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器
# xxxx 替换成自己的加速地址,加速页面:https://cr.console.aliyun.com/cn-beijing/instances/mirrors
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://xxxx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
升级和卸载docker
# 升级
yum -y upgrade docker-ce
# 卸载
yum remove docker-ce
# 删除Images, containers, volumes, or customized configuration files
rm -rf /var/lib/docker