Dokcer-ce安装脚本

安装docker
 1 #!/bin/bash
 2 # coding: utf-8
 3 # Copyright (c) 2018
 4 set -e #返回值为0时,退出脚本
 5 echo "1. 备份yum"
 6 {
 7 for i in /etc/yum.repos.d/*.repo;do cp $i ${i%.repo}.bak;done
 8 rm -rf /etc/yum.repos.d/*.repo
 9 } || {
10 echo "备份出错,请手动执行"
11 exit 1
12 }
13 
14 echo "2. 获取网络yum"
15 {
16 wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/Centos-7.repo >/dev/null 2>&1
17 wget -P /etc/yum.repos.d/ http://mirrors.163.com/.help/CentOS7-Base-163.repo >/dev/null 2>&1
18 yum clean >/dev/null 2>&1
19 yum repolist >/dev/null 2>&1
20 } || {
21 echo "获取出错,请手动执行"
22 exit 1
23 }
24 
25 echo "3. 安装docker-ce......" 
26 {
27 yum -y install yum-utils >/dev/null 2>&1
28 yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo >/dev/null 2>&1
29 yum clean >/dev/null 2>&1
30 yum repolist >/dev/null 2>&1
31 yum -y install epel-release docker-ce >/dev/null 2>&1
32 } || {
33 echo "安装出错,请手动安装"
34 exit 1
35 }
36 
37 systemctl start docker >/dev/null 2>&1
38 systemctl enable docker >/dev/null 2>&1
39 
40 echo "4. 添加内和参数"
41 {
42 cat <<EOF>> /etc/sysctl.conf 
43 net.bridge.bridge-nf-call-ip6tables = 1
44 net.bridge.bridge-nf-call-iptables = 1
45 EOF
46 sysctl -p >/dev/null 2>&1
47 }
48 
49 echo "5. 添加镜像加速"
50 {
51 cat <<EOF>> /etc/docker/daemon.json 
52 {
53 "registry-mirrors": [
54 "https://registry.docker-cn.com"
55 ]
56 }
57 EOF
58 }
59 
60 systemctl daemon-reload >/dev/null 2>&1
61 systemctl restart docker >/dev/null 2>&1
62 
63 rm -rf ./*.sh
View Code
原文地址:https://www.cnblogs.com/jay-fred/p/9956816.html