#!/bin/bash
repo="centos-yum.sh"
if [ ! -e $repo ]; then # -e 判断文件存在;参考:Shell if 条件判断文件或目录
yum install -y wget
wget www.eisc.cn/file/shell/centos-yum.sh ; sh centos-yum.sh
else
echo "yum已经切换"
fi
DockerInstall(){
dci=`rpm -qa | grep docker | wc -l`
if [ $dci -lt 1 ]
then
echo "正在安装docker =======》"
yum -y remove docker docker-common docker-selinux docker-engine
# 卸载旧版本docker
yum install -y yum-utils device-mapper-persistent-data lvm2
# 配置yum 源码
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# 添加docker yum 源码
yum list docker-ce --showduplicates | sort -r # 查看docker 版本
yum install -y docker-ce # 默认安装最新版本 docker
# yum install docker-ce-<VERSION_STRING> (指定安装版本)
# yum install docker-ce-18.03.1.ce
else
echo "已经成功安装docker"
fi
}
dockerCangku(){
mkdir -p /etc/docker; rm -rf /etc/docker/daemon.json; touch /etc/docker/daemon.json ; ls /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://hub-mirror.c.163.com"]
}
EOF
systemctl daemon-reload ; systemctl restart docker ; systemctl enable docker ; docker -v
# 重载docker配置,重启docker,加入开机启动
docker pull centos:7
# 拉取centos7 镜像
docker images
docker ps -a
#docker rmi -f nginx
}
DockerInstall
dockerCangku
# wget eisc.cn/file/shell/docker-install.sh ; sh docker-install.sh