安装docker 和docker-compose
#!/bin/bash
function docker_install()
{
echo "检测Docker是否安装..."
docker -v
if [ $? -ne 0 ]; then
echo "检测到Docker未安装!"
echo " ***** 开始安装 docker 工具 ***** "
ehco "添加docker软件源"
curl -o /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
echo "安装docker软件包"
yum -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin
echo "启动docker 并设置开机自启"
systemctl --now enable docker
echo "查看docker版本信息"
docker version
echo "docker安装完毕!"
else
echo "docker 已安装!"
fi
}
function docker-compose_install()
{
echo "检测docker-compose是否安装"
docker-compose version
if [ $? -ne 0 ]; then
echo "检测到docker-compose未安装"
echo " ***** 开始安装 docker-compose 工具 ***** "
curl -L http://mirror.azure.cn/docker-toolbox/linux/compose/v2.15.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
echo "查看docker-compose版本"
docker-compose version
echo "docker-compose 安装完毕!"
else
echo "docker-compose 已安装!"
fi
}
function docker-image_acceleration()
{
echo "配置docker 镜像加速"
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://tuv7rqqq.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
}
docker_install
docker-compose_install
docker-image_acceleration
标签:脚本,function,compose,ce,echo,docker,安装
From: https://www.cnblogs.com/scfssq/p/17393665.html