Linux系统——一键部署Docker(包含内网环境)

在线安装最新版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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值