docker和docker-compose安装脚本
1.docker安装脚本
1.1创建脚本文件
touch install_docker.sh
chmod 777 install_docker.sh
cat > install_docker.sh << 'EOF'
#!/bin/bash
# 删除现有的 Docker
echo -e "========== 1. 删除现有 Docker ================\n\n"
sudo yum remove -y docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
# 安装必要的一些系统工具
echo -e "Step 1: 安装必要的一些系统工具"
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# 添加软件源信息
echo -e "\n\nStep 2: 添加软件源信息,国内 Repository 更加稳定"
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 获取 CentOS 版本
version=$(cat /etc/redhat-release | sed -r 's/.* ([0-9]+)\..*/\1/')
if [ "$version" -eq 7 ]; then
echo -e "\n\nStep 3: 更新 CentOS version is : $version; 运行 yum makecache fast"
sudo yum makecache fast
elif [ "$version" -eq 8 ]; then
echo -e "\n\nStep 3: 更新 CentOS version is : $version; 运行 dnf makecache"
sudo dnf makecache
else
echo -e "不支持的 CentOS 版本: $version"
exit 1
fi
echo -e "=========== 2. 完成配置 Docker Repository ================\n\n"
# 安装最新版本的 Docker Engine 和 Container
sudo yum install -y docker-ce docker-ce-cli containerd.io
echo -e "=========== 3. 成功安装完 Docker ================\n\n"
# 启动 Docker 服务
sudo systemctl enable docker
sudo systemctl start docker
echo -e "=========== 4. 自启动 Docker ================\n\n"
# 创建 Docker 配置目录
sudo mkdir -p /etc/docker
# 编写配置文件
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://reg-mirror.qiniu.com",
"http://f1361db2.m.daocloud.io"
]
}
EOF
sh ./install_docker.sh
# 重载 Docker 配置并重启 Docker
sudo systemctl daemon-reload
sudo systemctl restart docker
echo -e "=========== 5. 配置国内镜像加速 ================\n\n"
# 显示 Docker 容器信息
docker ps -a
2.docker-compose
https://github.com/docker/compose/releases/download/v2.22.0/docker-compose-linux-x86_64
下载,手动传服务器,因为服务器wget太慢了
直接传到usr/local/bin然后给执行权限后续就能使用docker-compose命令
相关命令
chmod 777 /usr/local/bin/docker-compose-linux-x86_64
2024/9/9
安装docker脚本
bash <(curl -sSL https://cdn.jsdelivr.net/gh/SuperManito/LinuxMirrors@main/DockerInstallation.sh)
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose