centos7 docker离线安装脚本
2023-02-03 17:23:30
李朋利
  • 访问次数: 2
  • 注册日期: 2023-02-03
  • 最后登录: 2023-02-03

centos7 docker离线安装

运行该脚本须提前准备好相应离线包
#!/bin/bash
set -e
save_docker_dir=docker
docker_tar_name=docker-18.09.6.tgz
service_config_file=/etc/systemd/system/docker.service
if test -e $service_config_file
then 
    echo 'continue...'
    systemctl status docker
    docker -v
else
    tar -xvf $save_docker_dir/$docker_tar_name -C $save_docker_dir
    mv $save_docker_dir/docker/* /usr/bin
    rm -rf $save_docker_dir/docker
    echo '[Unit]' > $service_config_file
    echo 'Description=Docker Application Container Engine' >> $service_config_file
    echo 'Documentation=https://docs.docker.com' >> $service_config_file
    echo 'After=netword-online.target firewalld.service' >> $service_config_file
    echo 'Wants=network-online.target' >> $service_config_file
    echo '[Service]' >> $service_config_file
    echo 'Type=notify' >> $service_config_file
    echo 'ExecStart=/usr/bin/dockerd' >> $service_config_file
    echo 'ExecReload=/bin/kill -s HUP $MAINPID' >> $service_config_file
    echo 'LimitNOFILE=infinity' >> $service_config_file
    echo 'LimitNPROC=infinity' >> $service_config_file
    echo 'LimitCORE=infinity' >> $service_config_file
    echo 'TimeoutStartSec=0' >> $service_config_file
    echo 'Delegate=yes' >> $service_config_file
    echo 'KillMode=process' >> $service_config_file
    echo 'Restart=on-failure' >> $service_config_file
    echo 'StartLimitBurst=3' >> $service_config_file
    echo 'StartLimitInterval=60s' >> $service_config_file
    echo '[Install]' >> $service_config_file
    echo 'WantedBy=multi-user.target' >> $service_config_file
    echo 'continue...'
    chmod +x $service_config_file
    echo '...'
    systemctl daemon-reload
    echo '...'
    systemctl start docker
    echo '...'
    systemctl enable docker.service
    echo '...'
fi