docker离线一键安装脚本
下载安装文件
https://download.docker.com/linux/static/stable/x86_64/
https://github.com/docker/compose/releases
本例安装文件下载地址
https://download.docker.com/linux/static/stable/x86_64/docker-23.0.6.tgz
https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-linux-x86_64
安装脚本
参数1为docker数据目录,示例:
sh docker-install.sh /opt/docker
docker-install.sh
脚本内容:
#!/bin/bash
if [ ! -d $1 ]; then
mkdir -p $1
if [ $? -ne 0 ]; then
echo "$1 目录创建失败,请检查"
exit
fi
fi
ln -s $1 /var/lib/docker
ipv4_forward=$(sysctl -a |grep "net.ipv4.ip_forward =" |cut -d= -f2)
if [ $ipv4_forward -ne 1 ]; then
sed -i '/^net.ipv4.ip_forward\s*=/d' /etc/sysctl.conf
echo net.ipv4.ip_forward=1 >> /etc/sysctl.conf
sysctl -p
fi
#setup
tar -zxf docker-23.0.6.tgz && mv docker/* /usr/bin/ && rm -rf docker/
#systemd config
cat >/etc/systemd/system/docker.service << EOF
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
EOF
#start
chmod +x /etc/systemd/system/docker.service
systemctl daemon-reload && systemctl start docker && systemctl enable docker.service
#testing
systemctl status docker && docker -v
# 安装docker-compose
cp docker-compose-linux-x86_64 /usr/bin/docker-compose
chmod +x /usr/bin/docker-compose
docker-compose -v