注:二进制包,与脚本在同级目录

docker 离线安装:

  • 包下载:https://download.docker.com/linux/static/stable/x86_64/

docker_install.sh:

#!/bin/bash# 指定 Docker 版本和文件名DOCKER_VERSION="24.0.7"DOCKER_FILENAME="docker-${DOCKER_VERSION}.tgz"# 解压缩 Docker 二进制文件tar -xzf docker-24.0.7.tgz# 复制 Docker 二进制文件到 /usr/bin 目录sudo cp docker/* /usr/bin/# 创建 Docker 服务文件sudo tee /etc/systemd/system/docker.service << EOF[Unit]Description=Docker Application Container EngineDocumentation=https://docs.docker.comAfter=network-online.target firewalld.serviceWants=network-online.target[Service]Type=notifyExecStart=/usr/bin/dockerd -H unix://var/run/docker.sockExecReload=/bin/kill -s HUP $MAINPIDLimitNOFILE=infinityLimitNPROC=infinityLimitCORE=infinityTasksMax=infinityTimeoutStartSec=0Delegate=yesKillMode=process[Install]WantedBy=multi-user.targetEOF# 重新加载 systemd 配置sudo systemctl daemon-reload# 启动 Docker 服务sudo systemctl start docker# 设置 Docker 服务开机启动sudo systemctl enable dockerecho "Docker安装结束"

docker_remove.sh

#!/bin/bash# 删除 dockersudo systemctl stop dockersudo systemctl disable dockersudo rm -rf /etc/systemd/system/docker.servicesudo rm -rf /usr/bin/docker*sudo rm -rf /usr/bin/containerd*sudo rm -rf /var/run/docker*sudo rm -rf /var/lib/docker*sudo rm -rf /var/lib/containerd*echo "Docker卸载结束"

docker-compose 离线安装:

  • 包下载:https://github.com/docker/compose/releases

docker-compose_install.sh

#!/bin/bashsudo cp docker-compose-linux-x86_64 /usr/local/bin/docker-composesudo chmod +x /usr/local/bin/docker-composedocker-compose -vecho '安装结束'

docker-compose_remove.sh

#!/bin/bashsudo rm -rf /usr/local/bin/docker-composeecho '卸载结束'