Docker和docker-compose安装脚本-Ubuntu16.04
一、Docker and Docker-compose 安装脚本
具体脚本代码如下
#!/bin/bash
docker -v &>/dev/null
if [ $? == 0 ];thenecho -e "[*] docker-ce 已经存在..."echo -e "[*] 1、升级docker.\n2、卸载docker.\n3、卸载重新安装docker."read -p ""docker-compose -v &>/dev/nullif [ $? == 0 ];thenecho -e "[*] docker-compose 也已经存在..."echo -e "[*] 退出安装程序.....exit...."exitfi
fi
echo -e "[*] 开始更新源...."
apt-get update -y
#apt-get upgrade -y
if [ $? != 0 ];thenecho -e "[*] sudo ./docker-install.sh"exit
fiecho -e "[*] 开始安装 docker-ce..."
apt-get install docker-ce -y
if [ $? != 0 ];thenapt-get install -y apt-transport-https ca-certificates curl software-properties-commoncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable"apt-get updatecache=`apt-cache search docker-ce`if [ ! -n "$cache" ];thenecho -e "[*] 添加ali源....."curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"apt-get updatefiapt-get install docker-ce -yif [ $? != 0 ];thenprintf "Y\ny\n" | apt-get install docker-cefi
fidocker -v
if [ $? != 0 ];thenecho -e "[-] docker-ce 安装失败....."exit
elseecho -e "[+] docker-ce 安装成功....."
fiecho -e "[*] 开始安装 docker-compose....."
#apt install docker-compose -y
curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose --versionif [ $? == 0 ];thenecho -e "[+] docker-compose 安装成功....."
fi
运行安装脚本:
#给脚本被赋予用户执行权限
chmod u+x docker-install.sh
#执行脚本,开始安装
sudo ./docker-install.sh
二、升级版本~
升级版的安装脚本第一次安装如果有问题的话,进行第二次安装就行了。
#!/bin/bash###更新函数###
function update_source(){echo -e "[*] 开始更新源...."apt-get update -y#apt-get upgrade -yif [ $? != 0 ];thenecho -e "[*] sudo ./docker-install.sh"exitfi
}###安装docker-ce函数###
function install_docker_ce(){echo -e "[*] 开始安装 docker-ce..."apt-get install docker-ce -yif [ $? != 0 ];then#apt-get install -y apt-transport-https ca-certificates curl software-properties-commonprintf "Y\n" |apt-get install apt-transport-https ca-certificates curl gnupg lsb-release#curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -printf "Y\n" |curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg#add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable"echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullapt-get updatecache=`apt-cache search docker-ce`if [ ! -n "$cache" ];thenecho -e "[*] 添加ali源....."curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"apt-get update#apt-get install docker-ce -yfiapt-get install docker-ce docker-ce-cli containerd.io -yif [ $? != 0 ];thenprintf "Y\ny\n" | apt-get install docker-cefifidocker -vif [ $? != 0 ];thenecho -e "[-] docker-ce 安装失败.....";exitelseecho -e "[+] docker-ce 安装成功....."fi
}
###卸载docker-ce函数###
function remove_docker_ce(){ printf "Y\n" |apt-get remove docker docker-engine docker.io containerd runcprintf "Y\n" |apt-get purge docker-ce docker-ce-cli containerd.iorm -rf /var/lib/dockerrm -rf /var/lib/containerddocker -vif [ $? != 0 ];thenecho -e "[*] docker卸载成功..."elseecho -e "[-] docker-ce卸载失败..."echo -e "[-] sudo ./docker_install.sh";exitfi
}###安装docker-compose函数###
function install_docker_compose(){echo -e "[*] 开始安装 docker-compose....."#apt install docker-compose -y#下载docker稳定版.......curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-composechmod +x /usr/local/bin/docker-composeln -s /usr/local/bin/docker-compose /usr/bin/docker-composedocker-compose --versionif [ $? == 0 ];thenecho -e "[+] docker-compose 安装成功......"elseecho -e "[-] docker-compose 安装失败......"fi
}###卸载docker-compose-函数
function remove_docker_compose(){echo -e "[*] 开始卸载docker-compose..."rm /usr/local/bin/docker-composedocker-compose -vif [ $? != 0 ];thenecho -e "[*] docker-compose卸载成功..."elseecho -e "[-] docker-compose卸载失败...";exitfi
}docker -v &>/dev/null
if [ $? == 0 ];thenecho -e "[*] docker-ce 已经存在..."echo -e "1、升级docker.\n2、仅卸载docker.\n3、卸载重新安装docker."read -p "Please enter your choice?: " numif [ $num == 1 ];thenecho -e "[*] 开始升级docker-ce.."update_sourceinstall_docker_ceelif [ $num == 2 ];thenecho -e "[*] 开始卸载docker-ce..."remove_docker_ceelif [ $num == 3 ];thenecho -e "卸载重新安装docker-ce"remove_docker_ceupdate_sourceinstall_docker_ceelif [ $num == 'q' ];thenecho -e "[*] 退出安装docker-ce程序...";elseexitfi
elseupdate_sourceinstall_docker_ce
fidocker-compose -v &>/dev/null
if [ $? == 0 ];thenecho -e "[*] docker-compose 也已经存在..."echo -e "1、升级docker-compose.\n2、仅卸载docker-compose.\n3、卸载重新安装docker-compose."read -p "Please enter your choice?: " num2if [ $num2 == 1 ];thenecho -e "[*] 开始升级docker-compose..."echo -e "[*] 该功能在升级中..";exit#docker-compose migrate-to-labelselif [ $num2 == 2 ];thenremove_docker_composeelif [ $num2 == 3 ];thenecho -e "卸载重新安装docker-compose"remove_docker_composeupdate_sourceinstall_docker_composeelif [ $num2 == 'q' ];then echo -e "[*] 退出安装程序...";exitelseexitfi#echo -e "[*] 退出安装程序.....exit....";exit
elseupdate_sourceinstall_docker_compose
fi
要在桥接的模式下运行安装脚本!!:
参考文章:
- https://docs.docker.com/compose/install/#prerequisites
- https://docs.docker.com/engine/install/ubuntu/#install-using-the-convenience-script
Docker和docker-compose安装脚本-Ubuntu16.04相关推荐
- Win7下使用U盘安装linux Ubuntu16.04双系统图文教程
Win7下使用U盘安装linux Ubuntu16.04双系统图文教程 Ubuntu(友帮拓.优般图.乌班图)是一个以桌面应用为主的开源GNU/Linux操作系统,Ubuntu 是基于DebianGN ...
- 安装完Ubuntu16.04后要做的事
安装好Ubuntu16.04后要做的事 更新软件源 软件源使用国内比较知名的软件源例如163,清华,中科大等的软件源这些软件源的访问速度在国内也是比较快的. sudo vim /etc/apt/sou ...
- 毁灭者p6安装win10+Ubuntu16.04双系统血泪经验总结
在自己的毁灭者p6上安装win10+Ubuntu16.04,安到吐血,以下是血泪经验总结: 引子 首先制作iso镜像UltraISO.网上都有不多说. 然后,我是在默认的windows10 中去掉一个 ...
- 戴尔Latitude 3420:安装win10+ubuntu16.04双系统下找不到wifi
文章目录 前言 一.查看ubuntu内核版本 二.升级ubuntu内核 1.安装升级内核所需文件 2.下载对应的内核文件 3.安装5.3.5内核 三.安装驱动 1.重启遇到问题 2.安装驱动 前言 参 ...
- 游戏本(神舟战神Z7M-KP7GT)安装win10+Ubuntu16.04+显卡安装
1.游戏本(神舟战神Z7M-KP7GT)安装win10+Ubuntu16.04详细教程https://www.jianshu.com/p/888bb5ad02f3?utm_campaign=males ...
- 笔记本安装Win10+Ubuntu16.04 LTS 双系统
目标:安装Win10 + Ubuntu16.04 LTS 双系统 电脑:小米Air 13.3 高配版 工具: 硬件:U盘(2G就够,镜像包解压后文件大小为1.5G; FAT32格式, NTFS格式不识 ...
- Docker: 小白之路一(Ubuntu16.04安装篇)
Docker的小白之路 一.Docker的安装 1. ubuntu的安装 卸载旧版本: $ sudo apt-get remove docker docker-engine docker.io con ...
- linux系统脚本安装失败,ubuntu16.04下vim安装失败的原因分析及解决方案
先给大家说下问题描述? 重装了ubuntu系统,安装vim出现了以下问题: sudo apt-get install vim 正在读取软件包列表... 完成 正在分析软件包的依赖关系树 正在读取状态信 ...
- linux如何安装neo4j,Ubuntu16.04 如何安装neo4j数据库
什么是neo4j数据库? neo4j数据库是图数据库的一种,属于nosql的一种,常见的nosql数据库还有redis.memcached.mongDB等,不同于传统的关系型数据库,nosql数据也有 ...
最新文章
- sbt配置nexus仓库
- 打好网约车“安全牌”,T3出行以人、车、路保障
- iOS 9 学习系列:UIStack View
- 小车手app安卓版下载_古筝大师app下载-古筝大师下载v2.1.2 安卓版
- python里元组和列表的共同点和不同点_Python元组与列表的相同点与区别
- 治病花了130万才明白:不要轻易买保险
- 办公自动化-演练-从A表中提取数据整合到B表中-0223
- 域名型通配符ssl证书_西部数码使用指南:申请了主域名SSL证书,是否还需要申请www域名的...
- Android开发-无法新建Activity及新建后编译错误
- curviloft插件怎么用_Curviloft插件|SketchUp草图大师曲线放样插件(Curviloft)下载 v1.7d 免费版 - 比克尔下载...
- 软件测试:Lab 2 Selenium
- 大学计算机基础试题第一套,大学计算机基础试题及答案(完整版)
- html5表格制作教程,html怎么做表格
- 洛谷试炼场---提高历练地 普及练习场 新手村 入门难度
- win10截图快捷键是什么|win10截屏按键是哪个
- 如何以正确的顺序重新安装驱动程序
- 英文字母间距非常大的问题
- 如何合并多个excel表
- asp.Net Core 多线程之Task轻松学,快速上手
- Django 之 模型层