在线安装最新版Docker
#!/bin/bash
#需要在线环境
yum install -y yum-utils >/dev/null 2>&1
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo >/dev/null 2>&1
yum install -y docker-ce >/dev/null 2>&1
systemctl enable docker
systemctl start docker
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://0tzubha7.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
systemctl status docker >/dev/null 2>&1
return_code=$?
if [ $return_code -eq 0 ]; then
echo "恭喜!Docker部署完成。"
else
echo "Docker部署出错,请手动排查。"
fi
内网离线环境部署脚本
#!/bin/bash
#tar包需要在相对路径下
#Docker tar包下载地址:https://download.docker.com/linux/static/stable/x86_64/
tar -zxvf docker*.tgz -C /usr/local
cd /usr/local
cp docker/* /usr/bin
touch /etc/systemd/system/docker.socke
touch /etc/systemd/system/docker.service
touch /etc/systemd/system/containerd.service
tee /etc/systemd/system/docker.socket >/dev/null <<EOF
[Unit]
Description=Docker Socket for the API
PartOf=docker.service
[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker
[Install]
WantedBy=sockets.target
EOF
tee /etc/systemd/system/docker.service >/dev/null <<EOF
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target
[Service]
Type=notify
ExecStart=/usr/bin/dockerd --registry-mirror=http://3cda3ca9.m.daocloud.io -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
[Install]
WantedBy=multi-user.target
EOF
#这里换了个方法,用tee会报错
cat << EOF | sudo tee /etc/systemd/system/containerd.service > /dev/null
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target
[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd
Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=infinity
TasksMax=infinity
OOMScoreAdjust=-999
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
groupadd docker
systemctl start docker
systemctl enable docker.service
systemctl status docker >/dev/null 2>&1
return_code=$?
if [ $return_code -eq 0 ]; then
echo "恭喜!Docker部署完成。"
rm -rf /root/docker*.tgz
else
echo "Docker部署出错,请手动排查。"
fi