Linux安装docker以及配置镜像加速
安装docker
终端输入一键安装
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
可能会遇到这种错误
[root@centos8 wxf]# curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
# Executing docker install script, commit: 93d2499759296ac1f9c510605fef85052a2c32be
+ sh -c 'yum install -y -q yum-utils'
+ sh -c 'yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo'
添加仓库自:https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
+ '[' stable '!=' stable ']'
+ sh -c 'yum makecache'
CentOS Linux 8 - AppStream 2.6 kB/s | 4.3 kB 00:01
CentOS Linux 8 - BaseOS 5.9 kB/s | 3.9 kB 00:00
CentOS Linux 8 - Extras 2.3 kB/s | 1.5 kB 00:00
CentOS Linux 8 - PowerTools 8.9 kB/s | 4.3 kB 00:00
Docker CE Stable - x86_64 27 kB/s | 3.5 kB 00:00
Extra Packages for Enterprise Linux Modular 8 - x86_64 2.5 kB/s | 8.7 kB 00:03
Extra Packages for Enterprise Linux 8 - x86_64 1.0 kB/s | 7.4 kB 00:07
元数据缓存已建立。
+ '[' -n '' ']'
+ sh -c 'yum install -y -q docker-ce'
错误:
问题: problem with installed package buildah-1.19.7-1.module_el8.4.0+781+acf4c33b.x86_64
- package buildah-1.19.7-1.module_el8.4.0+781+acf4c33b.x86_64 requires runc >= 1.0.0-26, but none of the providers can be installed
- package buildah-1.21.4-2.module_el8.4.0+942+d25aada8.x86_64 requires runc >= 1.0.0-26, but none of the providers can be installed
- package buildah-1.21.4-1.module_el8.4.0+886+c9a8d9ad.x86_64 requires runc >= 1.0.0-26, but none of the providers can be installed
- package buildah-1.19.7-2.module_el8.4.0+830+8027e1c4.x86_64 requires runc >= 1.0.0-26, but none of the providers can be installed
出错执行这条指令
yum erase podman buildah
设置开机自启并启动docker
systemctl enable docker.service
systemctl start docker.service
测试
docker --version
sudo docker run hello-world
配置镜像加速
Docker 从 Docker Hub 拉取镜像,因为是从国外获取,所以速度较慢
可以通过配置国内镜像源的方式,从国内获取镜像,提高拉取速度。
创建/打开daemon.json文件
vim /etc/docker/daemon.json
输入以下下内容并保存
{
"registry-mirrors": ["http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"]
}
重新加载配置信息及重启 Docker 服务
# 重新加载某个服务的配置文件
sudo systemctl daemon-reload
# 重新启动 docker
sudo systemctl restart docker