docker的安装,自己写了一个安装docker的脚本,辅助做docker安装的实验(ubuntu)

#!/bin/bash
#获取用户名
[ pwd == '/root' ] && hn="root@$(hostname):~#" || hn="root@$(hostname):pwd#"
d (){
echo -e "\033[1m$hn$dd\033[0m"
}
a (){
sleep 1
}
c (){
echo -e "\033[32m$cc\033[0m"
}
#检查网络
ping -c 3 -i 0.2 -W 1 www.g.cn &> /dev/null
[ $? -ne 0 ] && echo "请检查你的网络是否畅通" && exit

read -p "请输入你的镜像加速地址.如https://rala1lg0.mirror.aliyuncs.com:" http

cc="步骤1 apt-get update 更新数据源" && c
dd="apt-get update" && d
apt-get update && a

cc="步骤2 安装所需依赖" && c
dd="apt-get -y install apt-transport-https ca-certificates curl software-properties-common" && d
apt-get -y install apt-transport-https ca-certificates curl software-properties-common && a

cc="步骤3 安装GPG证书" && c
dd="curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add" && d
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add && a

cc="步骤4 新增数据源" && c
dd='add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"' && d
add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs)
stable" && a

cc="步骤5 更新并安装 docker-ce " && c
dd="apt-get update && apt-get install -y docker-ce " && d
apt-get update && apt-get install -y docker-ce && a

cc="步骤6 验证是否安装成功 " && c
dd="docker version" && d
docker version && a

cc="步骤7 配置docker镜像加速器" && c
m1='"registry-mirrors"'
m2=': ["'
m3=$http
m4='"]'
m5=$m1$m2$m3$m4
dd="tee /etc/docker/daemon.json <<-'EOF'
{
$m5
}
EOF" && d
echo "{
$m5
}" > /etc/docker/daemon.json && a && cat /etc/docker/daemon.json
sudo systemctl daemon-reload
sudo systemctl restart docker
cc="查看镜像仓库多了加速地址" && c
dd="docker info" && d
docker info |tail -10 && a

cc="查看docker运行状态" && c
dd="service docker status" && d
service docker status |head -15 && a

cc="Hello-world程序验证Docker的正确安装" && c
dd="docker run hello-world" && d
docker run hello-world | head -10 && a

扫描二维码关注公众号,回复: 8919856 查看本文章

cc="Docker镜像,搜索Docker镜像" && c
dd="sudo docker search ubuntu" && d
sudo docker search ubuntu && a

cc="获取Docker镜像" && c
dd="sudo docker pull ubuntu" && d
sudo docker pull ubuntu & a

cc="获取mysql镜像" & c
dd="docker pull mysql" && d
docker pull mysql & a

cc="查看镜像" && c
dd="docker images" && d
docker images && a

cc="导出docker镜像,删除docker镜像" && c
dd="docker save ubuntu > /opt/ubuntu.tar.gz" && d
docker save ubuntu > /opt/ubuntu.tar.gz
sleep 5
dd="docker rmi ubuntu" && d
docker rmi ubuntu
dd="docker images" && d
docker images && a

cc="导入docker镜像" && c
dd="docker load < /opt/ubuntu.tar.gz" && d
docker load < /opt/ubuntu.tar.gz && a
sleep 5

cc="4.Docker容器,新建并运行容器,查看容器" && c
dd="docker run -itd ubuntu" && d
docker run -it ubuntu & a
dd="docker ps -a" && d
docker ps -a && a && sleep 3

cc="停止容器,删除容器" && c

gn (){
while :
do
x=docker ps -a |wc -l && let y=x-1
[ $y -eq 0 ] && echo "没有可以执行的容器,正在退出..." && sleep 3 && break
docker ps -a
read -p "请输入要停止、删除的完整的容器名,或按ctrl+c结束:" rq && [ -e $rq ] && continue
st=docker ps -a |tail -$y |grep "$rq" |cut -c1-12 |head -1
[ -e $st ] && echo "\033[31m$rq\033[0m不在容器中,容器中有以下服务:" && continue
dd="docker stop $st" && d
docker stop "$st" && a
dd="docker rm -f $st" && d
docker rm -f "$st"
done
}
x=docker ps -a |wc -l && let y=x-1
for i in seq $y
do
read -p "输入:[ls列出可以删除的docker容器][q退出]:" abc
case $abc in
q)
break;;
ls)
gn;;
*)
echo "输入不合法!" && gn;;
esac
done

猜你喜欢

转载自www.cnblogs.com/guarding/p/12203122.html
今日推荐