centos|centos8.2 离线安装docker

转载原文:https://blog.csdn.net/GentleLin/article/details/90294324
背景 由于公司内部服务器只能连内网,即使建立局域网yum源,也无法使用yum在线安装Docker CE。
支持在线安装的朋友们,直接参考CentOS在线安装Docker官方文档即可:https://docs.docker.com/install/linux/docker-ce/centos/
目前最新版本是v19.03.9。
准备工作 1、我使用得操作系统是centos8.2
查看CentOS版本,可通过下面命令查看:

cat /etc/redhat-release

2、下载docker-ce.repo文件
下载地址:https://download.docker.com/linux/centos/docker-ce.repo
3、下载最新的docker-ce、docker-ce-cli、containerd.io安装包
下载地址:https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
centos|centos8.2 离线安装docker
文章图片

注:截图中未出现的docker-ce-selinux安装包在新版本中已经被废弃了,需要下载另外的一个依赖包container-selinux
container-selinux安装包下载地址:https://pkgs.org/download/container-selinux
这个是我下载的链接:
http://mirror.centos.org/altarch/8/AppStream/armhfp/os/Packages/container-selinux-2.94-1.git1e99f1d.module_el8.1.0+132+34fc7673.noarch.rpm
开始安装 1、添加本地源,使用本地镜像制作本地源
centos|centos8.2 离线安装docker
文章图片

2、按顺序依次安装rpm包:
[root@localhost docker]# ls containerd.io-1.2.6-3.3.el7.x86_64.rpmcontainer-selinux-2.94-1.git1e99f1d.module_el8.1.0+132+34fc7673.noarch.rpmdocker-ce-19.03.9-3.el7.x86_64.rpmdocker-ce-cli-19.03.9-3.el7.x86_64.rpm [root@localhost docker]# yum localinstall *

3、安装成功后,启动docker
[root@localhost docker]# systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) Active: inactive (dead) Docs: https://docs.docker.com [root@localhost docker]# systemctl start docker [root@localhost docker]# systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) Active: active (running) since Thu 2020-09-03 10:58:31 CST; 886ms ago Docs: https://docs.docker.com Main PID: 23874 (dockerd) Tasks: 14 Memory: 45.3M CGroup: /system.slice/docker.service └─23874 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sockSep 03 10:58:31 localhost.localdomain dockerd[23874]: time="2020-09-03T10:58:31.001056624+08:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc Sep 03 10:58:31 localhost.localdomain dockerd[23874]: time="2020-09-03T10:58:31.182677680+08:00" level=warning msg="Your kernel does not support cgroup blkio weight" Sep 03 10:58:31 localhost.localdomain dockerd[23874]: time="2020-09-03T10:58:31.182710400+08:00" level=warning msg="Your kernel does not support cgroup blkio weight_device" Sep 03 10:58:31 localhost.localdomain dockerd[23874]: time="2020-09-03T10:58:31.183045714+08:00" level=info msg="Loading containers: start." Sep 03 10:58:31 localhost.localdomain dockerd[23874]: time="2020-09-03T10:58:31.638312936+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferr> Sep 03 10:58:31 localhost.localdomain dockerd[23874]: time="2020-09-03T10:58:31.823372666+08:00" level=info msg="Loading containers: done." Sep 03 10:58:31 localhost.localdomain dockerd[23874]: time="2020-09-03T10:58:31.891281500+08:00" level=info msg="Docker daemon" commit=9d988398e7 graphdriver(s)=overlay2 version=19.03.9 Sep 03 10:58:31 localhost.localdomain dockerd[23874]: time="2020-09-03T10:58:31.891627774+08:00" level=info msg="Daemon has completed initialization" Sep 03 10:58:31 localhost.localdomain dockerd[23874]: time="2020-09-03T10:58:31.989503175+08:00" level=info msg="API listen on /var/run/docker.sock" Sep 03 10:58:31 localhost.localdomain systemd[1]: Started Docker Application Container Engine. [root@localhost docker]# systemctl enable docker Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.

4、docker相关命令:
  • 查看:docker info
  • 重启:systemctl restart docker
  • 关闭:systemctl stop docker
四、可能出现的问题
1、在安装以上rpm包的时候,如果出现缺少依赖的错误,比如:
error: Failed dependencies: policycoreutils >= 2.5-11 is needed by container-selinux-2:2.95-2.el7_6.noarch selinux-policy >= 3.13.1-216.el7 is needed by container-selinux-2:2.95-2.el7_6.noarch selinux-policy-base >= 3.13.1-216.el7 is needed by container-selinux-2:2.95-2.el7_6.noarch selinux-policy-targeted >= 3.13.1-216.el7 is needed by container-selinux-2:2.95-2.el7_6.noarch

出现 “>=版本号”:说明你的系统上已经安装了这些包,只是这些包不是最新的,需要升级
以policycoreutils包为例,可以在https://pkgs.org/上搜索对应的最新的rpm包,执行以下命令进行升级:
# rpm -Uvh policycoreutils-2.5-29.el7.x86_64.rpm

如果对应的这个包被其它包依赖(policycoreutils被policycoreutils-python包依赖),这时会出现错误提示:
error: Failed dependencies: policycoreutils = 2.5-8.el7 is needed by (installed) policycoreutils-python-2.5-8.el7.x86_64

解决办法:先以不依赖的方式安装policycoreutils,再下载新的policycoreutils-python包升级。
# rpm -Uvh policycoreutils-2.5-29.el7.x86_64.rpm --nodeps # rpm -Uvh policycoreutils-python-2.5-29.el7.x86_64.rpm

其它类似错误,参考以上方法即可。
2、如果出现的是:
error: Failed dependencies: xxxxxx is needed by xxxxxxxxxxxxxxxxxx

【centos|centos8.2 离线安装docker】直接下载对应的包安装即可。

    推荐阅读