#!/bin/bash #Author: 柠檬班可优 #Date: 2019-06-06 #install docker in ubuntu and centos function install_docker_in_ubuntu { sudo apt-get update -y # install some tools sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common \ net-tools \ wget -y # install docker curl -fsSL get.docker.com -o get-docker.sh sh get-docker.sh # start docker service sudo groupadd docker &> /dev/null sudo gpasswd -a "${USER}" docker sudo systemctl start docker rm -rf get-docker.sh } function install_docker_in_centos { # install some tools sudo yum install -y git vim gcc glibc-static telnet bridge-utils # install docker curl -fsSL get.docker.com -o get-docker.sh sh get-docker.sh # start docker service sudo groupadd docker &> /dev/null sudo gpasswd -a "${USER}" docker sudo systemctl start docker rm -rf get-docker.sh } SYSTEM_NAME="$(awk -F= '/^NAME/{print $2}' /etc/os-release)" if [[ "${SYSTEM_NAME,,}" =~ "ubuntu" ]] ; then echo "Your system is ubuntu." echo "Installing Docker in ubuntu..." install_docker_in_ubuntu elif [[ "${SYSTEM_NAME,,}" =~ "centos" ]] ; then echo "Your system is centos." echo "Installing Docker in centos..." install_docker_in_centos else echo "This script can only run in ubuntu and centos system." exit 1 fi
时间: 2024-04-27 12:21:14 浏览: 167
CentOS 安装软件出现错误:/lib/ld-linux.so.2: bad ELF interpreter 解决
这段代码的作用是在 Ubuntu 或者 CentOS 系统中安装 Docker。代码中定义了两个函数 `install_docker_in_ubuntu` 和 `install_docker_in_centos`,分别用来在 Ubuntu 和 CentOS 系统中安装 Docker。在主函数中,通过检查系统名称来确定是在 Ubuntu 还是 CentOS 系统中运行脚本,然后调用相应的安装函数来安装 Docker。
代码的语法看起来没有问题,也没有出现之前提到的语法错误。如果你遇到了问题,可以把出错的信息贴出来,让我来帮你分析一下。
阅读全文