修复漏洞(一)离线升级Docker版本

前言

  • 一般人最好用的修复漏洞的方式就是更新版本
  • 起因是使用的Docker版本被检测出来有一堆漏洞(例如:Docker 操作系统命令注入漏洞(CVE-2019-5736))
  • 更新环境无法联网,只能通过下载二进制文件的形式进行安装

步骤

  • 可先通过which docker查看Docker可执行文件的地址
  • 然后查看自己docker的版本:docker versino
  • 停止并卸载原有Docker:
shell 复制代码
systemctl stop docker  # 停止Docker服务
yum remove docker docker-common docker-selinux docker-engine   # 卸载Docker(适用于CentOS)
  • 下载二进制文件:https://download.docker.com/linux/static/stable/x86_64/
    • 注意选择一个和原本Docker兼容的版本,具体啥兼容我也不知道,反正不要一次性版本更新太多,我第一次从19升级到24,然后后面死活构建不了镜像,最后选择了个20的最新版本,才成功构建镜像
  • 解压缩:tar xf docker-xxxxx.tgz
  • 复制文件:cp docker/* /usr/bin/
    • 后面这个地址指的是docker可执行文件的地址,默认是/usr/bin/目录下
    • 若提示覆盖,则选择覆盖即可
  • 设置开机自启:vi /etc/systemd/system/docker.service,内容如下
shell 复制代码
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target

[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
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target
  • 给执行权限
shell 复制代码
# 给执行权限
chmod +x /etc/systemd/system/docker.service
# 重新加载配置
systemctl daemon-reload
# 设置开机启动
systemctl enable docker.service
# 进行启动
systemctl start docker
  • 如果此时有报错,看看containered组件是否启动
shell 复制代码
# 查看containerd状态
systemctl status containerd
# 启动containerd服务
systemctl start containerd
  • 最后如果所有容器启动成功,通过Docker -version查看版本

提醒

  • 中间遇到了很多奇奇怪怪的Bug,就一点,先百度,百度解决不了就重启,注意不要随便用rm命令删除数据文件
  • 比如Docker启动不了,直接重启虚拟机
  • 如果容器启动不了,报啥端口占用啥的,直接重启Docker

参考

相关推荐
漫无目的行走的月亮2 小时前
在Docker中运行微服务注册中心Eureka
docker
大G哥4 小时前
记一次K8S 环境应用nginx stable-alpine 解析内部域名失败排查思路
运维·nginx·云原生·容器·kubernetes
大道归简5 小时前
Docker 命令从入门到入门:从 Windows 到容器的完美类比
windows·docker·容器
zeruns8025 小时前
如何搭建自己的域名邮箱服务器?Poste.io邮箱服务器搭建教程,Linux+Docker搭建邮件服务器的教程
linux·运维·服务器·docker·网站
爱跑步的程序员~5 小时前
Docker
docker·容器
福大大架构师每日一题6 小时前
23.1 k8s监控中标签relabel的应用和原理
java·容器·kubernetes
程序那点事儿6 小时前
k8s 之动态创建pv失败(踩坑)
云原生·容器·kubernetes
疯狂的大狗6 小时前
docker进入正在运行的容器,exit后的比较
运维·docker·容器
长天一色6 小时前
【Docker从入门到进阶】01.介绍 & 02.基础使用
运维·docker·容器
伊玛目的门徒6 小时前
docker 搭建minimalist-web-notepad
运维·docker·notepad