一键安装docker docker-compose
cat docker_install.sh
#!/bin/bash
set -e
#uninstall docker if exist
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
if [ `rpm -qa|grep docker|wc -l` -eq 0 ] ;
then
echo "############################"
echo "No Docker Version Installed!"
echo "############################"
else
rpm -e --nodeps $(rpm -qa|grep docker)
echo "#######################"
echo "Old Version Uninstalled"
echo "#######################"
fi
#install requirements
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
#setup repo
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
#list docker versions
yum list docker-ce --showduplicates | sort -r| grep 'el7'|awk {'print $2'}|grep '^3'|awk -F [:-] {'print $2'}
verrepo=`yum list docker-ce --showduplicates | sort -r| grep 'el7'|awk {'print $2'}|grep '^3'|awk -F [:-] {'print $2'}`
#read a version from keyboard
echo "##########################################################"
echo "select a version from above and type it down,like 19.03.5"
echo "##########################################################"
while true
do
read -p "Input a Version:" ver
if [ ${#ver} = 7 ] ;
then
if [[ $verrepo =~ $ver ]];
then
sudo yum install -y docker-ce-$ver docker-ce-cli-$ver containerd.io
break
else
echo "###############################"
echo "input error, input like 19.03.5"
echo "###############################"
fi
else
echo "###############################"
echo "input error, input like 19.03.5"
echo "###############################"
fi
done
#start docker service
echo "###############################"
echo "Starting Docker Service"
echo "###############################"
sudo systemctl start docker
ps -ef|grep docker|grep -v grep
echo "------------------------------------------------------------"
echo "------------------------------------------------------------"
docker version
echo "------------------------------------------------------------"
echo "------------------------------------------------------------"
if [ `ps -ef|grep docker |grep -v grep|wc -l`> 0 ] ;
then
echo "#######################"
echo "Docker Install Success!"
echo "#######################"
else
echo "######################"
echo "Docker Install Failed!"
echo "######################"
fi
cat docer-compose_install.sh
#!/bin/bash
set -e
# test if docker-compose exits
num=$(command -v docker-compose | wc -l)
echo $num
if [[ $num = 1 ]];
then
echo "###########################################"
echo "docker-compose already exits, see following"
echo "###########################################"
docker-compose version
echo "#########################################"
echo "wanna install latest version? type y or n"
echo "#########################################"
read -p "input your selection:" choose
case $choose in
"n")
echo "##########"
echo "exiting..."
echo "##########"
exit
;;
"y")
rm -f $(which docker-compose)
ver=$(curl -X GET https://api.github.com/repos/docker/compose/tags |grep "name"|grep -v docs|grep -v rc|awk -F[\"] {'print $4'}|sort -rV|head -n 1)
echo $ver
sudo curl -L "https://github.com/docker/compose/releases/download/$ver/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
;;
esac
else
echo "#########################"
echo "Installing docker-compose"
echo "#########################"
ver=$(curl -X GET https://api.github.com/repos/docker/compose/tags |grep "name"|grep -v docs|grep -v rc|awk -F[\"] {'print $4'}|sort -rV|head -n 1)
echo $ver
sudo curl -L "https://github.com/docker/compose/releases/download/$ver/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
fi
echo "######################"
echo "docker-compose version"
echo "######################"
docker-compose version
echo "################"
echo "Install Success!"
echo "################"
版权声明:
本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自
爱吃可爱多!
喜欢就支持一下吧
打赏
微信
支付宝