天天看點

linux centos 安裝docker shell腳本

#!/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