美文网首页
Centos7下docker环境的安装

Centos7下docker环境的安装

作者: 李小二的倔强 | 来源:发表于2022-10-31 17:10 被阅读0次

    红尘波浪两茫茫,忍辱求和是妙方。从来硬弩弦先断,自古钢刀口易伤。人为贪财身先死,鸟为夺食命早亡。任你奸猾多取巧,难免荒郊土内藏。

    docker架构图

    1.png

    方式一:

    1、yum 包更新
    [root@centos7 ~]# yum update
    
    2、卸载旧版本 Docker
    [root@centos7 ~]# yum remove docker docker-common docker-selinux docker-engine
    
    3、安装软件包
    [root@centos7 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
    
    4、添加 Docker yum源
    [root@centos7 ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    
    5、安装 Docker
    [root@centos7 ~]# yum -y install docker-ce
    
    6、启动 Docker
    [root@centos7 ~]# systemctl start docker
    
    7、查看 Docker 版本号
    [root@centos7 ~]# docker --version
    
    8、重启docker
    [root@centos7 ~]# service docker restart
    [root@centos7 ~]# systemctl restart  docker
    

    方式二:

    1、关闭防火墙、关闭selinux、关闭swapoff -a

    systemctl stop firewalld
    selinux=disabled
    swapoff -a
    

    2、安装docker

    1)常用方法
    a、配置yum源
    yum 包更新
    [root@centos7 ~] yum update
    [root@centos7 ~] yum -y install yum-utils
    阿里镜像源
    [root@centos7 ~] yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    Docker官方镜像源
    [root@centos7 ~] yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    
    b、安装docker
    显示docker-ce所有可安装版本:
    [root@centos7 ~] yum list docker-ce --showduplicates | sort -r
    安装指定docker版本
    [root@centos7 ~] yum install docker-ce-18.06.3.ce-3.el7  -y
    [root@centos7 ~] yum -y install docker-ce
    # centos8安装
    [root@centos8 ~]sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
    设置镜像存储目录
    找到大点的挂载的目录进行存储
    # 修改docker配置
    [root@centos7 ~] vi /lib/systemd/system/docker.service
    
    找到这行,往后面加上存储目录,例如这里是 --graph /apps/docker (此处也可以另外建一个文件去指定,详细参考下面方法)
    ExecStart=/usr/bin/dockerd --graph /mnt/data/docker
    启动docker并设置docker开机启动
    [root@centos7 ~] systemctl enable docker
    [root@centos7 ~] systemctl start docker
    

    centos8 执行安装docker命令 yum install docker-ce-18.06.3.ce-3.el7 -y 可能会出现 containerd.io 包版本过的不问题

    [root@localhost odc]# yum install docker-ce-20.10.9-3.el8   -y                
    Last metadata expiration check: 0:21:22 ago on Thu 04 Aug 2022 10:53:36 AM CST.
    Error: 
     Problem: package docker-ce-3:20.10.9-3.el8.x86_64 requires containerd.io >= 1.4.1, but none of the providers can be installed
      - package containerd.io-1.4.10-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.4.10-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.4.11-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.4.11-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.4.12-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.4.12-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.4.13-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.4.13-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.4.3-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.4.3-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.4.3-3.2.el8.x86_64 conflicts with runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.4.3-3.2.el8.x86_64 obsoletes runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.4.4-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.4.4-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.4.6-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.4.6-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.4.8-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.4.8-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.4.9-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.4.9-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.5.10-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.5.10-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.5.11-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.5.11-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.6.4-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.6.4-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.6.6-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.6.6-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - problem with installed package buildah-1.22.3-2.module_el8.5.0+911+f19012f9.x86_64
      - package buildah-1.22.3-2.module_el8.5.0+911+f19012f9.x86_64 requires runc >= 1.0.0-26, but none of the providers can be installed
      - conflicting requests
      - package runc-1.0.0-56.rc5.dev.git2abd837.module_el8.3.0+569+1bada2e4.x86_64 is filtered out by modular filtering
      - package runc-1.0.0-66.rc10.module_el8.5.0+1004+c00a74f5.x86_64 is filtered out by modular filtering
      - package runc-1.0.0-72.rc92.module_el8.5.0+1006+8d0e68a2.x86_64 is filtered out by modular filtering
    (try to add '--allowerasing' to command line to replace conflicting packages or '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
    

    解决方法:此时需要安装新版containerd.io,然后进下面这个链接 去看你所要的containerd.io版本
    https://download.docker.com/linux/centos/8/x86_64/stable/Packages/
    然后复制路径安装(我这个装的是1.4.3版本的 才更新没几天 如果后面有新的版本 直接换新的路径就好了)

    #执行命令
    yum install https://download.docker.com/linux/centos/8/x86_64/stable/Packages/containerd.io-1.4.3-3.1.el8.x86_64.rpm
    
    [root@localhost odc]# yum install https://download.docker.com/linux/centos/8/x86_64/stable/Packages/containerd.io-1.4.3-3.1.el8.x86_64.rpm
    Last metadata expiration check: 0:05:12 ago on Thu 04 Aug 2022 02:11:11 PM CST.
    containerd.io-1.4.3-3.1.el8.x86_64.rpm                                                                                                                                                                      8.3 MB/s |  33 MB     00:04    
    Error: 
     Problem: problem with installed package podman-3.3.1-9.module_el8.5.0+988+b1f0b741.x86_64
      - package podman-3.3.1-9.module_el8.5.0+988+b1f0b741.x86_64 requires runc >= 1.0.0-57, but none of the providers can be installed
      - package containerd.io-1.4.3-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - package containerd.io-1.4.3-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
      - conflicting requests
      - package runc-1.0.0-66.rc10.module_el8.5.0+1004+c00a74f5.x86_64 is filtered out by modular filtering
      - package runc-1.0.0-72.rc92.module_el8.5.0+1006+8d0e68a2.x86_64 is filtered out by modular filtering
    (try to add '--allowerasing' to command line to replace conflicting packages or '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
    

    上面bug 是CentOS 8 中安装 Docker 出现和 Podman 冲突的问题,解决方法如下

    #先把之前装的低版本的卸载掉
    sudo yum remove containerd.io
    

    再执行yum install https://download.docker.com/linux/centos/8/x86_64/stable/Packages/containerd.io-1.4.3-3.1.el8.x86_64.rpm便会成功,然后直接安装docker

    2)本地rpm包安装
    a)下载地址
    https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
    17版本请把docker-ce-selinux也一起下载
    b、创建挂在目录以及阿里源的文件
    mkdir -p /data/docker-root
    mkdir -p /etc/docker
    touch /etc/docker/daemon.json
    chmod 700 /etc/docker/daemon.json
    cat > /etc/docker/daemon.json << EOF
    {
    "graph":"/data/docker-root",
    "registry-mirrors": ["https://7bezldxe.mirror.aliyuncs.com"]
    }
    EOF
    c、安装docker
    yum localinstall ./docker* -y
    启动docker并设置docker开机启动
    systemctl enable docker
    systemctl start docker
    
    3)二进制安装
    a)下载地址
    二进制包下载地址:https://download.docker.com/linux/static/stable/x86_64/
    b)解压安装
    tar zxvf docker-18.09.6.tgz
    mv docker/* /usr/bin
    mkdir /etc/docker
    mkdir -p /data/docker-root
    mv daemon.json /etc/docker
    mv docker.service /usr/lib/systemd/system
    启动docker并设置docker开机启动
    systemctl start docker
    systemctl enable docker
    c)涉及到的daemon.json和docker.service的文件内容
    为了配置docker的目录和docker改为systemd以及阿里源
    cat > /etc/docker/daemon.json << EOF
    {
    "graph":"/data/docker-root",
    "registry-mirrors": ["https://7bezldxe.mirror.aliyuncs.com"]
    }
    EOF
    
    为了设置命令启动的
    cat > /usr/lib/systemd/system/docker.service << EOF
    [Unit]
    Description=Docker Application Container Engine
    Documentation=https://docs.docker.com
    After=network.target firewalld.service
    
    [Service]
    Type=notify
    # the default is not to use systemd for cgroups because the delegate issues still
    # exists and systemd currently does not support the cgroup feature set required
    # for containers run by docker
    ExecStart=/usr/bin/dockerd
    ExecReload=/bin/kill -s HUP $MAINPID
    # Having non-zero Limit*s causes performance problems due to accounting overhead
    # in the kernel. We recommend using cgroups to do container-local accounting.
    LimitNOFILE=infinity
    LimitNPROC=infinity
    LimitCORE=infinity
    # Uncomment TasksMax if your systemd version supports it.
    # Only systemd 226 and above support this version.
    #TasksMax=infinity
    TimeoutStartSec=0
    # set delegate yes so that systemd does not reset the cgroups of docker containers
    Delegate=yes
    # kill only the docker process, not all processes in the cgroup
    KillMode=process
    
    [Install]
    WantedBy=multi-user.target
    EOF
    
    

    卸载docker

    1.Uninstall the Docker Engine, CLI, and Containerd packages:(卸载Docker引擎、CLI和Containerd包:)

    $ sudo yum remove docker-ce docker-ce-cli containerd.io
    

    2.Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:(不会自动删除主机上的映像、容器、卷或自定义配置文件。要删除所有图像、容器和卷,请执行以下操作:)

    $ sudo rm -rf /var/lib/docker
    $ sudo rm -rf /var/lib/containerd
    

    You must delete any edited configuration files manually.(必须手动删除任何已编辑的配置文件。)

    相关文章

      网友评论

          本文标题:Centos7下docker环境的安装

          本文链接:https://www.haomeiwen.com/subject/qurltdtx.html