我是用的openEuler版本:20.03 LTS SP1,安装在虚拟机中,使用ssh连接
在openEuler上安装Docker还是让我踩了不少坑,先看看这些坑是如何产生的
虽然官方没有说openEuler是基于什么开源系统开发的,但大致内容和CentOS相似,首先参照官网文档安装步骤如下:
这里插一嘴,旧版本的Docker称为Docker或Docker Engine。17年改为基于YY.MM的版本, Docker Engine改为Docker CE(社区版),Docker Data Center改为Docker EE(企业版)
如果要卸载旧版本查看官方文档:https://docs.docker.com/engine/install/centos/#uninstall-old-versions
安装方法
官方给出了3种安装方法:
- 从Docker的存储库中安装(https://docs.docker.com/engine/install/centos/#install-using-the-repository)
- 下载RPM包并手动安装(https://docs.docker.com/engine/install/centos/#install-from-a-package)
- 使用自动化脚本(https://docs.docker.com/engine/install/centos/#install-using-the-convenience-script)
安装步骤
我使用第一种方法进行安装
-
因为需要用到
yum-config-manager
工具,所以需要安装yum-utils
包。之后使用yum-config-manager
添加docker-ce
的软件仓库sudo yum install -y yum-utils
软件仓库里找不到这个包,那好吧,添加仓库源
我是用的是华为云开源镜像站的镜像(https://mirrors.huaweicloud.com)
wget -O /etc/yum.repos.d/openEulerOS.repo https://repo.huaweicloud.com/repository/conf/openeuler_x86_64.repo yum clean all yum makecache
然后重新安装
yum-utils
sudo yum install -y yum-utils
居然还不行,再次我表示很郁闷,直接被卡在第一步了
在愤愤不平许久之后,发现系统自带
yum-config-manager
,顶着好奇的心查看了这个命令路径由于openEuler自带
dnf
包管理器,它直接建立一个链接指向dnf-utils
那我们直接执行下面语句,软件源官方较慢,我们使用国内镜像源。
sudo yum-config-manager \ --add-repo \ https://repo.huaweicloud.com/docker-ce/linux/centos/docker-ce.repo
注意的是使用华为镜像源需要执行以下命令替换文件中的部分内容:
sudo sed -i 's+download.docker.com+repo.huaweicloud.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
然后更新建立缓存:
sudo yum makecache
再次出了问题,
404
,难道是地址不对吗果然,再次分析发现:
cat /etc/yum.repos.d/docker-ce.repo
输出内容:
[docker-ce-stable] name=Docker CE Stable - $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/$releasever/$basearch/stable enabled=1 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-stable-debuginfo] name=Docker CE Stable - Debuginfo $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/$releasever/debug-$basearch/stable enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-stable-source] name=Docker CE Stable - Sources baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/$releasever/source/stable enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-test] name=Docker CE Test - $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/$releasever/$basearch/test enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-test-debuginfo] name=Docker CE Test - Debuginfo $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/$releasever/debug-$basearch/test enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-test-source] name=Docker CE Test - Sources baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/$releasever/source/test enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-nightly] name=Docker CE Nightly - $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/$releasever/$basearch/nightly enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-nightly-debuginfo] name=Docker CE Nightly - Debuginfo $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/$releasever/debug-$basearch/nightly enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-nightly-source] name=Docker CE Nightly - Sources baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/$releasever/source/nightly enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg
其中
$releasever
代表当前系统的版本,$basearch
代表当前系统的架构查看系统信息:
cat /etc/os-release
输出:
NAME="openEuler" VERSION="20.03 (LTS-SP1)" ID="openEuler" VERSION_ID="20.03" PRETTY_NAME="openEuler 20.03 (LTS-SP1)" ANSI_COLOR="0;31"
查看系统架构:
arch
输出:
x86_64
由于使用
CentOS
中的Docker
软件源安装,且https://repo.huaweicloud.com/docker-ce/linux/centos/中没有名为20.03LTS_SP1
的版本,我们只好手动更改软件源:将
$releasever
替换为7
(至于为什么替换为7
而不是8
,在安装过程中测试8
存在部分问题)[docker-ce-stable] name=Docker CE Stable - $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/7/$basearch/stable enabled=1 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-stable-debuginfo] name=Docker CE Stable - Debuginfo $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/7/debug-$basearch/stable enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-stable-source] name=Docker CE Stable - Sources baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/7/source/stable enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-test] name=Docker CE Test - $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/7/$basearch/test enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-test-debuginfo] name=Docker CE Test - Debuginfo $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/7/debug-$basearch/test enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-test-source] name=Docker CE Test - Sources baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/7/source/test enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-nightly] name=Docker CE Nightly - $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/7/$basearch/nightly enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-nightly-debuginfo] name=Docker CE Nightly - Debuginfo $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/7/debug-$basearch/nightly enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-nightly-source] name=Docker CE Nightly - Sources baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/7/source/nightly enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg
删掉
/etc/yum.repos.d/
下的docker-ce.repo
文件,使用vi docker-ce.repo
建立文件后将上面替换完成的内容粘贴进去保存。然后更新建立缓存:
sudo yum makecache
在插一嘴,
yum-config-manager
其实就是一个方便管理软件源的脚本,完全可以手动下载软件源到配置目录。wget -O /etc/yum.repos.d/docker-ce.repo https://repo.huaweicloud.com/docker-ce/linux/centos/docker-ce.repo sudo sed -i 's+download.docker.com+repo.huaweicloud.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo sudo yum makecache
这么也没多写多少字母,其实复制粘贴不就解决问题了。
-
安装最新版本的Docker Engine和containerd
sudo yum install docker-ce docker-ce-cli containerd.io
又出问题了,查找软件源中是否存在此包:
yum search fuse-overlayfs yum search slirp4netns
其结果都是:
上次元数据过期检查:0:05:30 前,执行于 2021年07月01日 星期四 19时56分15秒。 未找到匹配项。
没有软件源就添加软件源:
wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo
注意再次将此文件中的
$releasever
替换为7
# CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-7 - Base - repo.huaweicloud.com baseurl=https://repo.huaweicloud.com/centos/7/os/$basearch/ #mirrorlist=https://mirrorlist.centos.org/?release=7&arch=$basearch&repo=os gpgcheck=1 gpgkey=https://repo.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-7 - Updates - repo.huaweicloud.com baseurl=https://repo.huaweicloud.com/centos/7/updates/$basearch/ #mirrorlist=https://mirrorlist.centos.org/?release=7&arch=$basearch&repo=updates gpgcheck=1 gpgkey=https://repo.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-7 - Extras - repo.huaweicloud.com baseurl=https://repo.huaweicloud.com/centos/7/extras/$basearch/ #mirrorlist=https://mirrorlist.centos.org/?release=7&arch=$basearch&repo=extras gpgcheck=1 gpgkey=https://repo.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-7 - Plus - repo.huaweicloud.com baseurl=https://repo.huaweicloud.com/centos/7/centosplus/$basearch/ #mirrorlist=https://mirrorlist.centos.org/?release=7&arch=$basearch&repo=centosplus gpgcheck=1 enabled=0 gpgkey=https://repo.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7
删掉
/etc/yum.repos.d/
下的CentOS-Base.repo
文件,使用vi CentOS-Base.repo
建立文件后将上面替换完成的内容粘贴进去保存。yum clean all yum makecache
再次安装
sudo yum install docker-ce docker-ce-cli containerd.io
启动Docker
sudo service docker start
命令会重定向至 /bin/systemctl start docker.service
当然直接使用 systemctl start docker.service
也无所谓
通过运行hello-world镜像,验证Docker引擎是否正确安装。
sudo docker run hello-world
这个命令下载一个测试镜像并在一个容器中运行。当容器运行时,它会打印出一条信息消息并退出。
总结
结论1(推荐)
-
建立
docker-ce.repo
[docker-ce-stable] name=Docker CE Stable - $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/7/$basearch/stable enabled=1 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-stable-debuginfo] name=Docker CE Stable - Debuginfo $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/7/debug-$basearch/stable enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-stable-source] name=Docker CE Stable - Sources baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/7/source/stable enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-test] name=Docker CE Test - $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/7/$basearch/test enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-test-debuginfo] name=Docker CE Test - Debuginfo $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/7/debug-$basearch/test enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-test-source] name=Docker CE Test - Sources baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/7/source/test enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-nightly] name=Docker CE Nightly - $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/7/$basearch/nightly enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-nightly-debuginfo] name=Docker CE Nightly - Debuginfo $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/7/debug-$basearch/nightly enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-nightly-source] name=Docker CE Nightly - Sources baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/7/source/nightly enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg
在
/etc/yum.repos.d/
下的使用vi docker-ce.repo
建立文件后将上面的内容粘贴进去保存。 -
建立
CentOS-Base.repo
# CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-7 - Base - repo.huaweicloud.com baseurl=https://repo.huaweicloud.com/centos/7/os/$basearch/ #mirrorlist=https://mirrorlist.centos.org/?release=7&arch=$basearch&repo=os gpgcheck=1 gpgkey=https://repo.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-7 - Updates - repo.huaweicloud.com baseurl=https://repo.huaweicloud.com/centos/7/updates/$basearch/ #mirrorlist=https://mirrorlist.centos.org/?release=7&arch=$basearch&repo=updates gpgcheck=1 gpgkey=https://repo.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-7 - Extras - repo.huaweicloud.com baseurl=https://repo.huaweicloud.com/centos/7/extras/$basearch/ #mirrorlist=https://mirrorlist.centos.org/?release=7&arch=$basearch&repo=extras gpgcheck=1 gpgkey=https://repo.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-7 - Plus - repo.huaweicloud.com baseurl=https://repo.huaweicloud.com/centos/7/centosplus/$basearch/ #mirrorlist=https://mirrorlist.centos.org/?release=7&arch=$basearch&repo=centosplus gpgcheck=1 enabled=0 gpgkey=https://repo.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7
在
/etc/yum.repos.d/
下使用vi CentOS-Base.repo
建立文件后将上面的内容粘贴进去保存。 -
建立缓存
yum clean all yum makecache
-
安装软件
sudo yum install docker-ce docker-ce-cli containerd.io
结论2
直接从镜像站地址获取特定版本的软件及依赖(docker-ce
版本20.10.7
)
yum install \
https://repo.huaweicloud.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-20.10.7-3.el7.x86_64.rpm \
https://repo.huaweicloud.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-rootless-extras-20.10.7-3.el7.x86_64.rpm \
https://repo.huaweicloud.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-20.10.7-3.el7.x86_64.rpm \
https://repo.huaweicloud.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-scan-plugin-0.8.0-3.el7.x86_64.rpm \
https://repo.huaweicloud.com/docker-ce/linux/centos/7/x86_64/stable/Packages/containerd.io-1.4.6-3.1.el7.x86_64.rpm \
http://mirror.centos.org/centos/7/extras/x86_64/Packages/fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm \
http://mirror.centos.org/centos/7/extras/x86_64/Packages/slirp4netns-0.4.3-4.el7_8.x86_64.rpm