linux部署docker脚本

###GPW

#!/bin/env bash

## Author:SuperManito

## 定义变量:

## 判定系统是基于 Debian 还是 RedHat

ls /etc | grep redhat-release -qw

if [ $? -eq 0 ]; then

SYSTEM="RedHat"

else

SYSTEM="Debian"

fi

## 系统判定变量(系统名称、系统版本、系统版本号)

if [ $SYSTEM = "Debian" ]; then

SYSTEM_NAME=$(lsb_release -is)

SYSTEM_VERSION=$(lsb_release -cs)

SYSTEM_VERSION_NUMBER=$(lsb_release -rs)

elif [ $SYSTEM = "RedHat" ]; then

SYSTEM_NAME=$(cat /etc/redhat-release | cut -c1-6)

if [ $SYSTEM_NAME = "CentOS" ]; then

SYSTEM_VERSION_NUMBER=$(cat /etc/redhat-release | cut -c22-24)

CENTOS_VERSION=$(cat /etc/redhat-release | cut -c22)

elif [ $SYSTEM_NAME = "Fedora" ]; then

SYSTEM_VERSION_NUMBER=$(cat /etc/redhat-release | cut -c16-18)

fi

fi

## 环境搭建:

function Installation() {

if [ $SYSTEM_NAME = "Ubuntu" ]; then

apt remove -y docker docker-engine docker.io containerd runc

apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -

add-apt-repository -y "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

apt update

apt install -y docker-ce docker-ce-cli containerd.io

elif [ $SYSTEM_NAME = "Debian" ]; then

apt remove -y docker docker-engine docker.io containerd runc

apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common

curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -

add-apt-repository -y "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/debian $(lsb_release -cs) stable"

apt update

apt install -y docker-ce docker-ce-cli containerd.io

elif [ $SYSTEM_NAME = "Kali" ]; then

apt remove -y docker docker-engine docker.io containerd runc

apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common

curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -

add-apt-repository -y "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/debian $(lsb_release -cs) stable"

apt update

apt install -y docker-ce docker-ce-cli containerd.io

elif [ $SYSTEM_NAME = "CentOS" ]; then

yum remove -y docker* runc

yum install -y yum-utils device-mapper-persistent-data lvm2

yum-config-manager -y --add-repo https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo

yum makecache

yum install -y docker-ce docker-ce-cli containerd.io

elif [ $SYSTEM_NAME = "Fedora" ]; then

yum remove -y docker* runc

yum -y install yum-utils device-mapper-persistent-data lvm2

yum config-manager -y --add-repo https://mirrors.ustc.edu.cn/docker-ce/linux/fedora/docker-ce.repo

yum makecache

yum install -y docker-ce docker-ce-cli containerd.io

fi

## 创建目录和文件

mkdir -p /etc/docker

touch /etc/docker/daemon.json

## 配置阿里云镜像加速器

echo '{"registry-mirrors": ["https://registry.cn-hangzhou.aliyuncs.com"]}' >/etc/docker/daemon.json

## 启动 Docker 进程

systemctl enable --now docker

}

Installation

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值