openEuler安装Docker和踩坑分析

去年12 月 8 日,CentOS 开发团队在其官博宣布,CentOS 8 将在 2021 年 12 月 31 日结束支持,CentOS 7 会按照计划维护至生命周期结束即 2024 年 6 月 30 日,接下来接下来将重点建设 CentOS Stream。免费的RedHat没有了,但生活还得继续。

接下来我的目光转向openEuler,openEuler 是一个开源、免费的 Linux 发行版平台,将通过开放的社区形式与全球的开发者共同构建一个开放、多元和架构包容的软件生态体系。它由华为公司开源,众多国内企业也积极加入到openEuler社区,其社区发展之速度令人吃惊,堪称是中国开源领域的里程碑。

文章目录

      • 进入正题
      • 安装方法
      • 安装步骤
      • 启动Docker
      • 通过运行hello-world镜像,验证Docker引擎是否正确安装。
      • 总结
        • 结论1(推荐)
        • 结论2

进入正题

如果想忽略过程请直接查看结论:结论

我是用的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)

安装步骤

我使用第一种方法进行安装

  1. 因为需要用到yum-config-manager工具,所以需要安装yum-utils包。之后使用 yum-config-manager 添加docker-ce的软件仓库

    sudo yum install -y yum-utils
    

    image-20210701221806707

    openEuler安装Docker和踩坑分析_第1张图片

    软件仓库里找不到这个包,那好吧,添加仓库源

    我是用的是华为云开源镜像站的镜像(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
    

    image-20210701222717286

    居然还不行,再次我表示很郁闷,直接被卡在第一步了

    在愤愤不平许久之后,发现系统自带yum-config-manager,顶着好奇的心查看了这个命令路径

    image-20210701224004778

    由于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
    

    image-20210701225704777

    再次出了问题,404,难道是地址不对吗

    openEuler安装Docker和踩坑分析_第2张图片

    果然,再次分析发现:

    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
    

    这么也没多写多少字母,其实复制粘贴不就解决问题了。

  2. 安装最新版本的Docker Engine和containerd

    sudo yum install docker-ce docker-ce-cli containerd.io
    

    openEuler安装Docker和踩坑分析_第3张图片

    又出问题了,查找软件源中是否存在此包:

    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
    

    openEuler安装Docker和踩坑分析_第4张图片

启动Docker

sudo service docker start

命令会重定向至 /bin/systemctl start docker.service

当然直接使用 systemctl start docker.service也无所谓

通过运行hello-world镜像,验证Docker引擎是否正确安装。

 sudo docker run hello-world

openEuler安装Docker和踩坑分析_第5张图片

这个命令下载一个测试镜像并在一个容器中运行。当容器运行时,它会打印出一条信息消息并退出。

总结

结论1(推荐)
  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建立文件后将上面的内容粘贴进去保存。

  2. 建立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建立文件后将上面的内容粘贴进去保存。

  3. 建立缓存

    yum clean all
    yum makecache
    
  4. 安装软件

    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

你可能感兴趣的:(All,Linux,linux,openEuler)