#!/bin/bash

#
if [ ${#DOCKER_DATA_DIR} -eq 0 ]; then
  echo -e "\033[31;1m请确保您已经设置了环境变量DOCKER_DATA_DIR \033[0m"
  echo 当前DOCKER_DATA_DIR=$DOCKER_DATA_DIR
  exit 1
fi

# 卸载旧版本
yum remove -y docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine

# 设置 yum repository
yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

yum makecache fast

# 安装并启动 docker
rm -rf /var/lib/docker
yum install -y docker-ce-26.1.4 docker-ce-cli-26.1.4 containerd.io

systemctl enable docker
systemctl start docker

# 修改docker 镜像路径 使用docker info查看, 设置源
systemctl stop docker
rm -rf $DOCKER_DATA_DIR
mkdir -p $DOCKER_DATA_DIR 
mv /var/lib/docker $DOCKER_DATA_DIR
ln -sf $DOCKER_DATA_DIR/docker /var/lib/docker
systemctl start docker

