代码:
#!/bin/bashSYSTEMD_PATH=/usr/lib/systemd/system/docker.service
DOCKER_FILE=docker-20.10.23.tgz
DOCKER_COMPOSE_FILE=docker-compose-plugin-2.15.1-3.el8.x86_64.rpm
RED='\E[1;31m'
GREEN='\E[1;32m'
YELOW='\E[1;33m'
SHAN='\E[1;31;5m'
RES='\E[0m'function install_docker_system
{if ! which docker;thenecho -e "${RED}[+]No docker command, Begin install docker...${RES}"#cd ./deploytar -zxvf $DOCKER_FILEcp docker/* /usr/bin/fiif [ ! -f "$SYSTEMD_PATH" ];thenecho """[Unit]Description=Docker serviceRequires=network.targetAfter=network.target[Service]Type=simpleExecStart=/usr/bin/dockerdStartLimitBurst=3000PIDfile=/var/run/docker.pidRestart=always[Install]WantedBy=basic.target """ > $SYSTEMD_PATHchmod +x $SYSTEMD_PATHsystemctl daemon-reloadsystemctl restart dockersleep 3sfidocker ps > /dev/null 2>&1if [ $? -eq 0 ];thenecho -e "${GREEN}[+]Docker install successed!${RES}"fiif ! which docker-compose;thenecho -e "${RED}[+]No docker-compose command,Begin install docker-compose...${RES}"rpm -ivh $DOCKER_COMPOSE_FILE( echo '#!/bin/bash'; echo 'docker compose $@' ) > /bin/docker-composechmod 755 /bin/docker-composefiwhich docker-composeif [ $? -eq 0 ];thenecho -e "${GREEN}[+]Docker-compose install successed!${RES}"fi
}
function uninstall_docker_system
{echo "Stop docker systemd..."systemctl stop dockerfor i in `ls docker`;do rm -v /usr/bin/"$i";donerm -v $SYSTEMD_PATHecho -e "${GREEN}[+]Uninstall docker complete!${RES}"for w in `rpm -qa | grep docker-compose`;do rpm -e --nodeps $w;donerm -v /usr/bin/docker-composeecho -e "${GREEN}[+]Uninstall docker-compose complete!${RES}"
}
case "$1" ininstall)install_docker_system;;uninstall)uninstall_docker_system
esac
exit 0
运行结果: