docker自动部署脚本

docker自动部署脚本

1、检查内核版本;

2、检查docker是否已安装;

3、安装docker,如因网络等原因失败循环安装至安装完成;

#!/bin/bash 
#file:docker_install.sh 
function docker_install()
{
  echo "--检查内核版本......--"
  yum -y install bc &> /dev/null
  kenel=`uname -r`
  kenel=`echo ${kenel:0:3}`
  if [ $(echo "${kenel} >= 3.10" | bc) = 1 ];then
    echo "--检查Docker......!--"
    docker -v &> /dev/null
    a=`echo $?`
    while [ $a -ne 0 ]; do
      echo "--安装docker环境...--"
      echo "--安装基础依赖...--"
      yum install yum-utils device-mapper-persistent-data lvm2 -y &> /dev/null
      echo "--安装docker-ce.repo--"
      yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo &> /dev/null
      yum update &> /dev/null
      yum makecache fast &> /dev/null
      echo "--安装docker环境...--"
      yum install containerd.io docker-ce docker-ce-cli -y
      docker -v &> /dev/null
      a=`echo $?`
    done
    echo "--安装完成!启动Docker--"
    systemctl start docker
    systemctl enable docker &> /dev/null
    else
  echo "--内核版本太低,请您升级内核版本!--"
 
  fi
}

执行函数:

docker_install

镜像加速:

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://gbpursha.mirror.aliyuncs.com"]    #自己的镜像加速地址
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

docker 部署微服务:(dockerfile)

十分钟学会用docker部署微服务_docker_脚本之家 (jb51.net)

docker-compose部署:

curl -L "https://github.com/docker/compose/releases/download/1.21.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
#或者这个
curl -L https://github.com/docker/compose/releases/download/1.24.0-rc3/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 --version

docker使用大全集:

https://www.cnblogs.com/williamjie/p/9103327.html

docker compose部署常用中间件:

nginx、Tomcat、redis、mysql等

docker compose部署prometheus:

https://blog.csdn.net/weixin_45727359/article/details/109554890

https://blog.csdn.net/miss1181248983/article/details/107415551

prometheus基于consul自动发现:

https://blog.csdn.net/weixin_59410846/article/details/121863024?spm=1001.2014.3001.5502

docker基于consul自动发现:

https://blog.csdn.net/weixin_53060366/article/details/122813647?spm=1001.2014.3001.5501

你可能感兴趣的:(docker容器,docker,运维)