#!/bin/bash
# 内网安装docker
# docker 下载地址：https://download.docker.com/linux/static/stable/x86_64/
which docker &>/dev/null
if [ $? -ne 0 ];then
wget https://download.docker.com/linux/static/stable/x86_64/docker-23.0.1.tgz
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://hub-mirror.c.163.com","https://registry.aliyuncs.com","https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn"],
    "data-root": "$docker_dir",
    "log-driver":"json-file",
    "log-opts": {"max-size":"1024m", "max-file":"3"}
}
EFO
systemctl daemon-reload
systemctl enable docker
systemctl restart docker.service
else
   docker --version
fi