shell腳本
#!/bin/sh
# 當(dāng)前目錄
CURRENT_DIR=$(
cd "$(dirname "$0")"
pwd
)
#Install docker
if which docker >/dev/null; then
echo "檢測(cè)到 Docker 已安裝,跳過(guò)安裝步驟"
docker -v
echo "啟動(dòng) Docker "
service docker start 2>&1 | tee -a ${CURRENT_DIR}/install.log
else
if [[ -d "$CURRENT_DIR/docker" ]]; then
echo "... 離線安裝 docker"
cp $CURRENT_DIR/docker/centos-local.tgz /root/
cd /root && tar -xvzf centos-local.tgz
cd /root/docker-ce-local &&rpm -ivh createrepo-0.9.9-28.el7.noarch.rpm
mkdir -p /etc/yum.repos.d/repobak && mv /etc/yum.repos.d/CentOS* /etc/yum.repos.d/repobak
cp $CURRENT_DIR/docker/docker-ce-local.repo /etc/yum.repos.d/docker-ce-local.repo
cd /root/docker-ce-local &&createrepo /root/docker-ce-local && yum makecache
cd $CURRENT_DIR/docker/ &&yum install -y container-selinux-2.9-4.el7.noarch.rpm &&yum install -y docker-ce
echo "... 啟動(dòng) docker"
sudo systemctl start docker 2>&1 | tee -a ${CURRENT_DIR}/install.log
echo '{"registry-mirrors":["https://registry.docker-cn.com"]}'>/etc/docker/daemon.json
cat /etc/docker/daemon.json
service docker restart
else
echo "... 在線安裝 docker"
curl -fsSL https://get.docker.com -o get-docker.sh 2>&1 | tee -a ${CURRENT_DIR}/install.log
sudo sh get-docker.sh 2>&1 | tee -a ${CURRENT_DIR}/install.log
echo "... 啟動(dòng) docker"
service docker start 2>&1 | tee -a ${CURRENT_DIR}/install.log
fi
fi
##Install Latest Stable Docker Compose Release
if which docker-compose >/dev/null; then
echo "檢測(cè)到 Docker Compose 已安裝,跳過(guò)安裝步驟"
docker-compose -v
else
if [[ -d "$CURRENT_DIR/docker-compose" ]]; then
echo "... 離線安裝 docker-compose"
cd $CURRENT_DIR/docker-compose/ && cp docker-compose /usr/local/bin/
chmod +x /usr/local/bin/docker-compose
docker-compose -version
echo "... 離線安裝 docker-compose 成功"
else
echo "... 在線安裝 docker-compose"
curl -L "https://github.com/docker/compose/releases/download/1.14.0-rc2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose 2>&1 | tee -a ${CURRENT_DIR}/install.log
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose -version
echo "... 在線安裝 docker-compose 成功"
fi
fi
如果腳本復(fù)制后使用報(bào)下面的錯(cuò)誤
請(qǐng)執(zhí)行
sed -i 's/\r$//' installDocker.sh
chmod +x installDocker.sh
在網(wǎng)絡(luò)條件不好的情況下建議離線安裝,請(qǐng)先下載下面的包
離線的安裝包
鏈接: https://pan.baidu.com/s/1ANDM5v-Z1zmljekc4djAdQ
提取碼: 39dm
到此這篇關(guān)于docker和docker-compose一鍵安裝(支持在線和離線)的文章就介紹到這了,更多相關(guān)docker和docker-compose安裝內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!