1 docker安装与配置
1.1 版本声明
name | version | |
---|---|---|
OS | CentOS | 7.7.1908 |
core | Linux | 3.10.0-1062.el7.x86_64 |
container | docker | 20.10.2 |
1.2 查看环境
// 查看Linux发行商名称和版本
[root@localhost ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
...
// 查看发行商详细版本
[root@localhost ~]# cat /etc/centos-release
CentOS Linux release 7.7.1908 (Core)
// 查看Linux内核版本
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-1062.el7.x86_64 #1 SMP Wed Aug 7 18:08:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
1.3 安装docker
// 1.卸载旧版本docker
yum remove docker docker-client docker-client-latest docker-common \
docker-latest docker-latest-logrotate docker-logrotate docker-engine
// 2.下载依赖包
yum install -y yum-utils
// 3.设置镜像仓库为阿里云
yum-config-manager --add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
// 4.更新yum软件包缓存
yum makecache fast
// 5.安装docker引擎
yum install docker-ce docker-ce-cli containerd.io
* 图示已去水印,供下载使用
1.4 docker安装测试
// 启动docker服务
systemctl start docker
// 查看docker版本号, 检验是否安装成功
[root@localhost ~]# docker version
Client: Docker Engine - Community
Version: 20.10.2
API version: 1.41
...
Server: Docker Engine - Community
Engine:
Version: 20.10.2
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
...
// 运行hello-world镜像
[root@localhost ~]# docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
2 docker加速配置
使用阿里云容器镜像服务的镜像加速器。
* 图示已去水印,供下载使用
// 配置阿里云镜像加速
cp /lib/systemd/system/docker.service /etc/systemd/system/docker.service
chmod 777 /etc/systemd/system/docker.service
vim /etc/systemd/system/docker.service
// 将docker.service文件中的
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
// 替换为
ExecStart=/usr/bin/dockerd --registry-mirror=https:// .mirror.aliyuncs.com
// 重启docker服务
systemctl daemon-reload
systemctl restart docker
[root@localhost ~]# docker info
...
Registry Mirrors:
https:// .mirror.aliyuncs.com/
3 参考文献
[1][澳]詹姆斯•特恩布尔(James Turnbull).第一本Docker书[M].人民邮电出版社,2014.