第八节.Docker-ce自动安装脚本

系统环境Centos7最小化安装,配置静态IP可以PING通外网,DNS未配置

#!/bin/bash

#############################################################################
function shutdown_selinux_firewalld(){
    sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
    cat /etc/selinux/config|grep =|grep disabled
    sed -i '/$/a\nameserver 114.114.114.114\nnameserver 221.228.255.1' /etc/resolv.conf
    ping -c 4 www.baidu.com
    systemctl stop firewalld
    systemctl disable firewalld
    systemctl status firewalld
}
#############################################################################
#############################################################################
function change_yum_repo(){
    yum install -y yum-utils
    mkdir /etc/yum.repos.d/repod.bak
    mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repod.bak
    cd /etc/yum.repos.d/
    yum-config-manager  --add-repo  http://mirrors.aliyun.com/repo/Centos-7.repo
    yum-config-manager  --add-repo  http://mirrors.163.com/.help/CentOS7-Base-163.repo
    yum-config-manager  --add-repo  http://mirrors.aliyun.com/repo/epel-7.repo
    yum-config-manager  --add-repo  https://download.docker.com/linux/centos/docker-ce.repo
    yum-config-manager  --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    yum clean all
    yum makecache
    yum list | grep epel-release
    yum install -y epel-release
    yum clean all
    yum makecache
    yum repolist enabled
    yum repolist all
    yum install -y tree vim  wget net-tools
}
#############################################################################
#############################################################################
function install_docker_ce(){
    yum remove docker docker-client docker-client-latest docker-common docker-latest  docker-latest-logrotate  docker-logrotate  docker-selinux  docker-engine-selinux docker-engine
    yum install -y device-mapper-persistent-data lvm2   
    yum install -y iptables-services
    systemctl enable iptables
    systemctl start iptables
    yum install docker-ce  -y
    systemctl enable docker
    systemctl start docker
    systemctl status iptables
    systemctl status docker
    echo -e "{\n\t\"registry-mirrors\": [ \"https://registry.docker-cn.com\" ]\n}" >/etc/docker/daemon.json  
    docker pull hello-world
    docker run hello-world
}   
##############################################################################
shutdown_selinux_firewalld
change_yum_repo
install_docker_ce

可以查看所有仓库中所有docker版本,并选择特定版本安装

$ yum list docker-ce --showduplicates | sort -r

你可能感兴趣的:(第八节.Docker-ce自动安装脚本)