脚本安装docker
使用脚本在不同发行版linux 上安装 docker
脚本内容:
# cat installdocker.sh
#!/bin/bash
DOCKER_VER="28.0.1"
DOCKER_FILE="docker-${DOCKER_VER}.tgz"
# "x86_64" or "aarch64"
SYS_ARCH="x86_64"
DOCKER_URL="https://download.docker.com/linux/static/stable/${SYS_ARCH}"
SRC_DIR="/tools"
## Initialize the environment And Install Tools
. /etc/os-release
if [ $ID_LIKE=debian ]; then
apt -y update && apt install -y tar vim bash-completion
[ $? -ne 0 ] && { echo "Install Toosl Failed" ; exit; }
apt remove -y docker docker-common docker-selinux docker-engine docer-io
dpkg -l | egrep "iptables|ufw" &>/dev/null || apt install -y ufw
if ufw status &>/dev/null; then
ufw disable
echo 'ufw is complete closed'
else
echo 'ufw is closed'
fi
else
dnf makecache && dnf install -y tar vim-enhanced bash-completion
[ $? -ne 0 ] && { echo "Install Toosl Failed" ; exit; }
dnf remove -y docker docker-common docker-selinux docker-engine docer-io
rpm -qa | egrep "iptables-nft|firewalld" &>/dev/null || dnf -y install firewalld
selinux_code=$(getenforce)
if [ ${selinux_code} = 'Disabled' ]; then
echo 'Selinux closed'
else
setenforce 0
sed -i '/^SELINUX=/c SELINUX=disabled' /etc/selinux/config
echo 'Selinux Temporarily Shutdown, and Permanent After Restarting'
fi
if firewall-cmd --state &>/dev/null; then
systemctl disable --now firewalld.service &>/dev/null
echo 'firewalld is complete closed'
else
echo 'firewalld is closed'
fi
fi
## DownloadFiles
[ ! -d ${SRC_DIR} ] && mkdir ${SRC_DIR}
if [ -e ${SRC_DIR}/${DOCKER_FILE} ];then
echo "The DockerFile is ready"
else
echo 'Start download Docker Package'
curl ${DOCKER_URL}/${DOCKER_FILE} -o ${SRC_DIR}/${DOCKER_FILE}
[ $? -ne 0 ] && { echo "Download ${DOCKER_FILE} Failed" ; exit; }
fi
cd ${SRC_DIR}
tar -xvf ${DOCKER_FILE}
cp -af docker/* /usr/bin/
## Service
cat > /usr/lib/systemd/system/docker.service <<EOF
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
# BindsTo=containerd.service
# After=network-online.target firewalld.service containerd.service
After=network-online.target firewalld.service
Wants=network-online.target
# Requires=docker.socket
[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 fd:// --containerd=/run/containerd/containerd.sock
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP \$MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3
# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s
# 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
# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
# TasksMax=infinity
# 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
[Install]
WantedBy=multi-user.target
EOF
mkdir /etc/docker/ /data/docker -pv
cat > /etc/docker/daemon.json <<EOF
{
"data-root": "/data/docker",
"storage-driver": "overlay2",
"live-restore": true
}
EOF
## Start Service
systemctl daemon-reload
systemctl enable --now docker.service
systemctl status docker.service
执行脚本
bash installdocker.sh
转载请注明作者和出处,并添加本页链接。
原文链接:
//www.wwtou.com/rd0a4xDs.html