安装docker
#!/bin/bash
# coding: utf-8
# Copyright (c) 2018
set -e #返回值为0时,退出脚本
echo "1. 备份yum"
{
for i in /etc/yum.repos.d/*.repo;do cp $i ${i%.repo}.bak;done
rm -rf /etc/yum.repos.d/*.repo
} || {
echo "备份出错,请手动执行"
exit 1
}

echo "2. 获取网络yum"
{
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/Centos-7.repo >/dev/null 2>&1
wget -P /etc/yum.repos.d/ http://mirrors.163.com/.help/CentOS7- -163.repo >/dev/null 2>&1
yum clean >/dev/null 2>&1
yum repolist >/dev/null 2>&1
} || {
echo "获取出错,请手动执行"
exit 1
}

echo "3. 安装docker-ce......"
{
yum -y install yum-utils >/dev/null 2>&1
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo >/dev/null 2>&1
yum clean >/dev/null 2>&1
yum repolist >/dev/null 2>&1
yum -y install epel-release docker-ce >/dev/null 2>&1
} || {
echo "安装出错,请手动安装"
exit 1
}

systemctl start docker >/dev/null 2>&1
systemctl enable docker >/dev/null 2>&1

echo "4. 添加内和参数"
{
cat <<EOF>> /etc/sysctl.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl -p >/dev/null 2>&1
}

echo "5. 添加镜像加速"
{
cat <<EOF>> /etc/docker/daemon.json
{
"registry-mirrors": [
"https://registry.docker-cn.com"
]
}
EOF
}

systemctl daemon-reload >/dev/null 2>&1
systemctl restart docker >/dev/null 2>&1

rm -rf ./*.sh

收藏 打印