#!/bin/bash
# 查找Docker-CE的版本:
# yum list docker-ce.x86_64 --showduplicates | sort -r

# 准备 https://developer.aliyun.com/mirror/docker-ce
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
sudo yum makecache

# 安装docker
sudo yum -y install docker-ce
systemctl start docker.service
systemctl enable docker.service

# docker数据目录 Docker Root Dir迁移到home下, 默认是在 /var/lib/docker
docker info
systemctl stop docker
mkdir -p /home/docker
mv /var/lib/docker /home/docker
ln -s /home/docker /var/lib/docker
systemctl start docker
docker info
docker version

# 安装docker-compose
# https://github.com/docker/compose/releases/download/v2.26.1/docker-compose-linux-x86_64
curl -L http://58.220.49.186:9999/common/docker-compose-linux-x86_64 > /usr/bin/docker-compose
chmod 755 /usr/bin/docker-compose
sudo chmod +x /usr/bin/docker-compose
docker-compose --version

# 添加host
echo 58.220.49.186 harbor.cqt.com >> /etc/hosts

# 配置
mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
      "registry-mirrors": [
        "https://hub-mirror.c.163.com",
        "https://docker.mirrors.ustc.edu.cn"
    ],
    "insecure-registries" : [ "harbor.cqt.com:11000" ],
    "log-driver":"json-file",
    "log-opts": {"max-size":"100m", "max-file":"10"},
    "data-root": "/home/docker"
}
EOF

# 重启
systemctl restart docker

# 服务器登录harbor
docker login -u admin --password cqt@1234 http://harbor.cqt.com:11000
