#!/bin/bash
wget https://download.docker.com/linux/static/stable/x86_64/docker-23.0.1.tgz
if [ $? -ne 0 ];then
   echo "https://download.docker.com/linux/static/stable/x86_64/docker-23.0.1.tgz 包下载失败..."
   exit 3
fi
tar -zxvf docker-23.0.1.tgz
mv docker/* /usr/bin
rm -rf docker*
cat >/usr/lib/systemd/system/docker.service<<EFO
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
 
[Service]
Type=notify
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
 
[Install]
WantedBy=multi-user.target
EFO
# 自定义docker安装路径
docker_dir=/pdata1/docker
ls /etc/docker &>/dev/null || mkdir -p /etc/docker
ls $docker_dir &>/dev/null || mkdir -p $docker_dir
cat > /etc/docker/daemon.json << EFO
{
    "registry-mirrors":["https://docker.mirrors.ustc.edu.cn","http://hub-mirror.c.163.com"],
    "insecure-registries": ["122.9.97.179:8080","http://119.91.196.44:8111"],
    "data-root": "$docker_dir",
    "log-driver":"json-file",
    "log-opts": {"max-size":"1G", "max-file":"3"}
}
EFO
systemctl daemon-reload
systemctl enable docker
systemctl restart docker.service