docker 前言
Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 Linux或Windows 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。
docker 参考
docker | docker-compose |
download | download |
Linux 各系统下载使用参考
Red Hat | Rocky Linux | Oracle Linux | AlmaLinux | ubuntu | suselinux | esxi | RHEL标准安装 | 系统安装参考 | YUM参考 | MobaXterm 远程连接工具 | Red Hat Enterprise 9.0 文档 | Kickstart 生成器 | |||||
download | download | download | download | download | download | download | 参考 | 参考 | 配置参考 | download | 参考 | Kickstart | |||||
版本兼容性 |
安装 docker,docker_compose
-
创建安装自动化脚本
- 实现在线安装docker,docker_compose,环境变量,系统服务,防火墙配置,企业微信机器人通知。
- 以下基于Redhat系统
- /opt/docker 安装目录
- curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXXXX' #更改自己的企业微信机器人地址
- curl -o /etc/yum.repos.d/redhat.repo http://mirrors.aliyun.com/repo/Centos-8.repo #阿里在线repo
- yum install figlet -y #用于将文字转换为放大艺术字(使用figlet Mysql显示)
vi /docker_install.sh
#!/bin/sh
# -*- coding: utf-8 -*-
# Author: CIASM
# update 2023/04/12
<<!
██████╗ ██████╗ ██████╗██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██╔════╝██║ ██╔╝██╔════╝██╔══██╗
██║ ██║██║ ██║██║ █████╔╝ █████╗ ██████╔╝
██║ ██║██║ ██║██║ ██╔═██╗ ██╔══╝ ██╔══██╗
██████╔╝╚██████╔╝╚██████╗██║ ██╗███████╗██║ ██║
╚═════╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
!
<<!
#Centos 8 依赖安装
yum install -y wget yum-utils device-mapper-persistent-data lvm2 git vim net-tools slirp4netns fuse3-libs fuse-overlayfs fuse3 libslirp libcgroup
!
#Define docker path variables
docker_url=https://download.docker.com/linux/static/stable/x86_64
docker_tgz=docker-23.0.3.tgz
docker_download=/opt
DOCKER_PREFIX=/opt/docker
#Define docker-compose path variables
docker_compose_url=https://github.com/docker/compose/releases/download/v2.17.2
docker_compose=docker-compose-linux-x86_64
install_rely (){
yum install -y wget device-mapper-persistent-data lvm2 git vim net-tools slirp4netns fuse3-libs fuse-overlayfs fuse3 libslirp libcgroup
rpm -ivh https://yum.oracle.com/repo/OracleLinux/OL8/baseos/latest/x86_64/getPackage/yum-utils-4.0.21-14.1.0.1.el8.noarch.rpm --nodeps --force
}
install_docker (){
if [ ! -d ${DOCKER_PREFIX} ];then
install_rely
wget -N -P $docker_download $docker_url/$docker_tgz
tar -xf $docker_download/$docker_tgz -C $docker_download
ln -s $DOCKER_PREFIX/* /usr/bin/
if [ $? -eq 0 ];then
echo 'export DOCKER_HOME=/opt/docker' >> /etc/profile
source /etc/profile
install_docker_compose
docker_config
action "\033[32mThe docker Install Sussess...\033[0m"
else
action "\033[33mThe docker Install Failed...\033[0m"
exit 1
fi
else
echo -e "\033[31mThe docker already Install...\033[0m"
fi
}
install_docker_compose (){
wget -N -P $docker_download $docker_compose_url/$docker_compose
mv $docker_download/$docker_compose /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
}
docker_config (){
cat >>/usr/lib/systemd/system/docker.service<<EOF
[Unit]
Description=Docker Application Container Engine
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now docker
rm -rf $docker_download/$docker_tgz
}
Deployment_completion_notification (){
host_ID=`dmidecode -s system-serial-number | sed -r 's/\s+//g'`
host_IP=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2}' | awk 'NR==1'`
memory_Size=`dmidecode -t memory | grep Size | grep -v No | awk '{sum+=$2} END {printf "%.0fG\n",sum/1^C4}'`
CPU_Model=`cat /proc/cpuinfo | grep 'model name' | awk '{print $6}' | uniq`
Disk_size=`fdisk -l | grep "sda:" | awk '{print $3$4}'`
redhat_version=`cat /etc/redhat-release | grep "release" | awk '{print $6}'`
redhat_core=`cat /proc/version | grep "version" | awk '{print $3}'`
docker_version=`docker --version | awk '{print $3}'`
docker_compose_version=`docker-compose --version | awk '{print $4}'`
docker_server=`systemctl status docker | grep "Active" | awk '{print $2}'`
curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXXX' \
-H 'Content-Type: application/json' \
-d '
{
"msgtype": "markdown",
"markdown": {
"content": " **system check** <font color=\"info\"> complete </font> \n
> **Host IP Address** \n
[http://'$host_IP'](http://'$host_IP') \n
> **Hardware information** \n
hostSN:<font color=\"info\"> '$host_ID' </font> \n
CPU_Model:<font color=\"info\"> '$CPU_Model' </font> \n
memory_Size:<font color=\"info\"> '$memory_Size' </font> \n
Disk_size:<font color=\"info\"> '$Disk_size' </font> \n
System_version:<font color=\"info\"> '$redhat_version' </font> \n
system_core:<font color=\"info\"> '$redhat_core' </font> \n
> **docker install** \n
docker_version:<font color=\"info\"> '$docker_version' </font> \n
docker_compose_version:<font color=\"info\"> '$docker_compose_version' </font> \n
docker_server:<font color=\"info\"> '$docker_server' </font> \n",
}
}'
}
man (){
install_docker
Deployment_completion_notification
}
man
执行安装
sh /docker_install.sh