欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

Dokcer-ce安装脚本

程序员文章站 2022-07-01 22:39:59
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%.re ......
安装docker
Dokcer-ce安装脚本
 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