脚本安装docker

/

使用脚本在不同发行版linux 上安装 docker

脚本内容:

  1. # cat installdocker.sh
  1. #!/bin/bash
  2. DOCKER_VER="28.0.1"
  3. DOCKER_FILE="docker-${DOCKER_VER}.tgz"
  4. # "x86_64" or "aarch64"
  5. SYS_ARCH="x86_64"
  6. DOCKER_URL="https://download.docker.com/linux/static/stable/${SYS_ARCH}"
  7. SRC_DIR="/tools"
  8. ## Initialize the environment And Install Tools
  9. . /etc/os-release
  10. if [ $ID_LIKE=debian ]; then
  11. apt -y update && apt install -y tar vim bash-completion
  12. [ $? -ne 0 ] && { echo "Install Toosl Failed" ; exit; }
  13. apt remove -y docker docker-common docker-selinux docker-engine docer-io
  14. dpkg -l | egrep "iptables|ufw" &>/dev/null || apt install -y ufw
  15. if ufw status &>/dev/null; then
  16. ufw disable
  17. echo 'ufw is complete closed'
  18. else
  19. echo 'ufw is closed'
  20. fi
  21. else
  22. dnf makecache && dnf install -y tar vim-enhanced bash-completion
  23. [ $? -ne 0 ] && { echo "Install Toosl Failed" ; exit; }
  24. dnf remove -y docker docker-common docker-selinux docker-engine docer-io
  25. rpm -qa | egrep "iptables-nft|firewalld" &>/dev/null || dnf -y install firewalld
  26. selinux_code=$(getenforce)
  27. if [ ${selinux_code} = 'Disabled' ]; then
  28. echo 'Selinux closed'
  29. else
  30. setenforce 0
  31. sed -i '/^SELINUX=/c SELINUX=disabled' /etc/selinux/config
  32. echo 'Selinux Temporarily Shutdown, and Permanent After Restarting'
  33. fi
  34. if firewall-cmd --state &>/dev/null; then
  35. systemctl disable --now firewalld.service &>/dev/null
  36. echo 'firewalld is complete closed'
  37. else
  38. echo 'firewalld is closed'
  39. fi
  40. fi
  41. ## DownloadFiles
  42. [ ! -d ${SRC_DIR} ] && mkdir ${SRC_DIR}
  43. if [ -e ${SRC_DIR}/${DOCKER_FILE} ];then
  44. echo "The DockerFile is ready"
  45. else
  46. echo 'Start download Docker Package'
  47. curl ${DOCKER_URL}/${DOCKER_FILE} -o ${SRC_DIR}/${DOCKER_FILE}
  48. [ $? -ne 0 ] && { echo "Download ${DOCKER_FILE} Failed" ; exit; }
  49. fi
  50. cd ${SRC_DIR}
  51. tar -xvf ${DOCKER_FILE}
  52. cp -af docker/* /usr/bin/
  53. ## Service
  54. cat > /usr/lib/systemd/system/docker.service <<EOF
  55. [Unit]
  56. Description=Docker Application Container Engine
  57. Documentation=https://docs.docker.com
  58. # BindsTo=containerd.service
  59. # After=network-online.target firewalld.service containerd.service
  60. After=network-online.target firewalld.service
  61. Wants=network-online.target
  62. # Requires=docker.socket
  63. [Service]
  64. Type=notify
  65. # the default is not to use systemd for cgroups because the delegate issues still
  66. # exists and systemd currently does not support the cgroup feature set required
  67. # for containers run by docker
  68. # ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
  69. ExecStart=/usr/bin/dockerd
  70. ExecReload=/bin/kill -s HUP \$MAINPID
  71. TimeoutSec=0
  72. RestartSec=2
  73. Restart=always
  74. # Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
  75. # Both the old, and new location are accepted by systemd 229 and up, so using the old location
  76. # to make them work for either version of systemd.
  77. StartLimitBurst=3
  78. # Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
  79. # Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
  80. # this option work for either version of systemd.
  81. StartLimitInterval=60s
  82. # Having non-zero Limit*s causes performance problems due to accounting overhead
  83. # in the kernel. We recommend using cgroups to do container-local accounting.
  84. LimitNOFILE=infinity
  85. LimitNPROC=infinity
  86. LimitCORE=infinity
  87. # Comment TasksMax if your systemd version does not support it.
  88. # Only systemd 226 and above support this option.
  89. # TasksMax=infinity
  90. # set delegate yes so that systemd does not reset the cgroups of docker containers
  91. Delegate=yes
  92. # kill only the docker process, not all processes in the cgroup
  93. KillMode=process
  94. [Install]
  95. WantedBy=multi-user.target
  96. EOF
  97. mkdir /etc/docker/ /data/docker -pv
  98. cat > /etc/docker/daemon.json <<EOF
  99. {
  100. "data-root": "/data/docker",
  101. "storage-driver": "overlay2",
  102. "live-restore": true
  103. }
  104. EOF
  105. ## Start Service
  106. systemctl daemon-reload
  107. systemctl enable --now docker.service
  108. systemctl status docker.service

执行脚本

  1. bash installdocker.sh

转载请注明作者和出处,并添加本页链接。
原文链接: //www.wwtou.com/rd0a4xDs.html