离线部署---docker

关键词:docker离线部署,images离线安装,docker compose,shell,minio

docker离线安装

docker install offline

下载相应的版本的deb包,我的系统是ubuntu20.04,因此选择focal文件夹,路径:

按照文档下载相应的包,挑选自己想要的版本。

从部署脚本中截取安装docker的部分:

#!/bin/bash

echo "Please run this script as root. Because it will install docker and docker-compose.
If you have installed docker and docker-compose, please ignore this message.
And i use docker-compose version is 3.8, so please make sure your docker engine version is 19.03.0+." echo # check user is root
whoami=$(whoami)
if [ "$whoami" != "root" ]; then
echo "Please run as root."
exit 1
fi # check docker is installed # verlt 24.0.5 19.03.0 && echo "yes" || echo "no" # no
# this function check $1 is less than $2
versionLessThan() {
if [ "$1" = "$2" ]; then
return 1
else
# sort -V: natural sort of (version) numbers within text
[ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ]
fi
} if ! which docker >/dev/null 2>&1; then echo "docker is not installed. Start install docker." # install docker use offline package
cd docker-install || exit sudo dpkg -i ./containerd.io_1.6.21-1_amd64.deb \
./docker-ce_24.0.2-1~ubuntu.20.04~focal_amd64.deb \
./docker-ce-cli_24.0.2-1~ubuntu.20.04~focal_amd64.deb \
./docker-buildx-plugin_0.10.5-1~ubuntu.20.04~focal_amd64.deb \
./docker-compose-plugin_2.18.1-1~ubuntu.20.04~focal_amd64.deb sudo service docker start cd ..
fi

如果当前机器已经安装docker了,那么我检查当前docker engine版本,我用的docker compose版本为3.8,因此我需要docker engine 大于等于 19.03.0

# check docekr engine version
docker_version=$(docker version --format '{{.Server.Version}}')
echo "docker engine version is $docker_version"
# if docker_version less than 19.03.0, exit
if versionLessThan "$docker_version" "19.03.0"; then
echo "docker engine version is less than 19.03.0, please upgrade docker engine."
exit 1
fi

离线安装镜像

将docker镜像备份:docker save -o yourImage.tar company/yourImage:v1.0

将备份的tar上传到离线的机器,加载镜像:docker load -i yourImage.tar

docker compose 启动容器

镜像加载好后,就可以用docker compose启动容器了

我的docker compose:

version: "3.8"
services:
cogent-admin:
container_name: cogent-admin
image: cogent/cogent-admin:v1.0
volumes:
- cogent-admin-data:/opt/cogent-admin/logs
- cogent-admin-data:/opt/cogent-admin/config
- cogent-admin-data:/opt/cogent-admin/uploadPath
- cogent-admin-data:/opt/device-upgrade-pack-repo
network_mode: "host"
depends_on:
- redis
- mysql
redis:
image: cogent/redis:v1.0
container_name: redis
command: redis-server /etc/redis/redis.conf --appendonly yes
volumes:
- redis-data:/data #数据文件挂载
- redis-data:/etc/redis
network_mode: "host"
mysql:
container_name: mysql
image: cogent/mysql:v1.0
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --default-time-zone='+08:00'
restart: always
environment:
MYSQL_DATABASE: 'cogent-admin'
MYSQL_ROOT_PASSWORD: root
volumes:
- mysql-data:/var/lib/mysql #数据文件挂载
- mysql-conf-data:/etc/mysql #配置文件挂载 记得设置时区,东八区
- mysql-log-data:/var/log/mysql #日志文件挂载
network_mode: "host"
mediakit:
image: zlmediakit/zlmediakit:Debug.latest
container_name: mediakit
volumes:
- mediakit-data:/opt/media/bin/log
- mediakit-data:/opt/media/conf/config.ini
network_mode: "host"
minio:
image: quay.io/minio/minio
container_name: minio
command: server /data --console-address=":9090" --address=":9002" --ftp="address=:8021" --ftp="passive-port-range=30000-40000"
environment:
MINIO_ROOT_USER: ROOTNAME
MINIO_ROOT_PASSWORD: CHANGEME123
MINIO_NOTIFY_WEBHOOK_ENABLE_PRIMARY: "on"
MINIO_NOTIFY_WEBHOOK_ENDPOINT_PRIMARY: "http://127.0.0.1:8080/buckets/event"
volumes:
- minio-data:/data
network_mode: "host" volumes:
cogent-admin-data:
mediakit-data:
mysql-data:
mysql-conf-data:
mysql-log-data:
redis-data:
minio-data:

mysql的数据文件不能和日志文件等放到一起,否则启动时会报错,说数据目录已经有文件

对应用进行初始化

如果你有在初次部署时有对某些应用进行初始化的操作,比如我需要在初次部署时,将minio创建Access key,创建默认bucket,开启webhook。那么可以在minio容器启动后:

# check minio is running
if pgrep -x "minio" >/dev/null; then
echo "minio init..."
# minio deploy: create access key and secret key, create bucket, webhook event
docker exec -i minio bash < minioDeploy.sh
else
echo "minio is not running. This will influence file upload and download."
fi

这样会在容器中执行minioDeploy.sh脚本。

minioDeploy.sh脚本内容:

#!/bin/bash

# minio deploy: create access key and secret key, create bucket, webhook event
chmod +x /opt/bin/mc
cd /opt/bin || exit
mc alias set myminio http://127.0.0.1:9002 ROOTNAME CHANGEME123
mc admin user svcacct add --access-key "xFkEokGRAlwIs1234" --secret-key "jaz4FlvCDDKvbBuQYJ9NIohMUlRDsT132465789" myminio ROOTNAME
mc mb myminio/cogent
mc event add myminio/cogent arn:minio:sqs::PRIMARY:webhook --event put
mc event add myminio/cogent arn:minio:sqs::PRIMARY:webhook --event delete

完整的部署脚本:

#!/bin/bash

echo "Please run this script as root. Because it will install docker and docker-compose.
If you have installed docker and docker-compose, please ignore this message.
And i use docker-compose version is 3.8, so please make sure your docker engine version is 19.03.0+." echo # check user is root
whoami=$(whoami)
if [ "$whoami" != "root" ]; then
echo "Please run as root."
exit 1
fi # check docker is installed # verlt 24.0.5 19.03.0 && echo "yes" || echo "no" # no
# this function check $1 is less than $2
versionLessThan() {
if [ "$1" = "$2" ]; then
return 1
else
# sort -V: natural sort of (version) numbers within text
[ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ]
fi
} if ! which docker >/dev/null 2>&1; then echo "docker is not installed. Start install docker." # install docker use offline package
cd docker-install || exit sudo dpkg -i ./containerd.io_1.6.21-1_amd64.deb \
./docker-ce_24.0.2-1~ubuntu.20.04~focal_amd64.deb \
./docker-ce-cli_24.0.2-1~ubuntu.20.04~focal_amd64.deb \
./docker-buildx-plugin_0.10.5-1~ubuntu.20.04~focal_amd64.deb \
./docker-compose-plugin_2.18.1-1~ubuntu.20.04~focal_amd64.deb sudo service docker start cd ..
fi echo "docker is installed."
# check docekr engine version
docker_version=$(docker version --format '{{.Server.Version}}')
echo "docker engine version is $docker_version"
# if docker_version less than 19.03.0, exit
if versionLessThan "$docker_version" "19.03.0"; then
echo "docker engine version is less than 19.03.0, please upgrade docker engine."
exit 1
fi # laod images
docker load -i redis.tar
docker load -i mysql.tar
docker load -i mediakit.tar
docker load -i cogent-admin.tar
docker load -i minio.tar # start docker containers
docker compose up -d redis mysql minio
docker compose up -d cogent-admin mediakit # check minio is running
if pgrep -x "minio" >/dev/null; then
echo "minio init..."
# minio deploy: create access key and secret key, create bucket, webhook event
docker exec -i minio bash < minioDeploy.sh
else
echo "minio is not running. This will influence file upload and download."
fi

离线部署-docker的更多相关文章

  1. 记离线部署docker,以及docker下部署zabbix

    一.离线安装docker 下载地址:https://download.docker.com/linux/static/stable/x86_64/ 上传软件并解压 [root@localhost op ...

  2. 微服务架构 - CentOS7离线部署docker

    1.环境准备 系统环境为: CentOS Linux release 7.5.1804 (Core) 安装docker版本为: 17.12.0-ce 2.准备部署文件 在http://mirrors. ...

  3. ubuntu 14.04 离线部署docker

    hett@hett-virtual-machine:~$ lsb_release -aNo LSB modules are available.Distributor ID:    UbuntuDes ...

  4. Centos7离线部署docker

    下载docker离线包 wget https://download.docker.com/linux/static/stable/x86_64/docker-19.03.5.tgz 解压 tar -x ...

  5. 微服务架构 - 离线部署k8s平台并部署测试实例

    一般在公司部署或者真实环境部署k8s平台,很有可能是内网环境,也即意味着是无法连接互联网的环境,这时就需要离线部署k8s平台.在此整理离线部署k8s的步骤,分享给大家,有什么不足之处,欢迎指正. 1. ...

  6. centos7.5离线安装Docker及容器运行报OCI runtime create failed 问题定位与解决

    前言 接上篇 <记一次centos挂载ceph存储的坑> 服务器重做了centos7.5版本的操作系统,剩下就是安装docker,考虑yum安装耗时较长,我一般都是直接安装二进制版本doc ...

  7. 离线手动部署docker镜像仓库——harbor仓库(HTTPS)

    实验环境: harbor服务器系统:CentOS Linux release 7.5.1804 (Core)harbor服务器IP:10.1.12.114harbor版本:v1.5.0docker版本 ...

  8. Linux系统如何在离线环境或内网环境安装部署Docker服务和其他服务

    如何在离线环境或纯内网环境的Linux机器上安装部署Docker服务或其他服务.本次我们以Docker服务和Ansible服务为例. 获取指定服务的所有rpm包 保证要获取rpm包的机器能够上网. 本 ...

  9. [转帖]在 Kubernetes 离线部署 KubeSphere

    在 Kubernetes 离线部署 KubeSphere https://kubesphere.io/docs/v2.0/zh-CN/installation/install-ks-offline/ ...

  10. 招商银行 KubeVela 离线部署实践

    招商银行云平台开发团队自 2021 年开始接触 KubeVela,并探索 KubeVela 在招商银行云平台的落地实践,借此提升云原生应用交付与管理能力.同时因为金融保险行业的特殊性,网络安全管控措施 ...

随机推荐

  1. 快速上手NPM包管理

    NPM官网 前提 安装nodejs 检测安装成功的命令 node -v 显示版本号即为安装成功 快速上手教程 第一步注册NPM账号官网在上面 第二步骤随便找个地方新建一个文件夹 然后这个文件夹我们用C ...

  2. windows幻灯片壁纸

    设置为10秒 win+r输入regedit 查找路径 HKEY_CURRENT_USER\Control Panel\Personalization\Desktop Slideshow 修改inter ...

  3. 从零开始配置vim(19)——终端配置

    在上一篇文章中,我们熟悉了终端模式,并且配置了终端模式的一些操作.但是它总是有那么一点不符合我们的使用习惯.这篇我们将通过强大的插件来完善终端操作的体验. 在介绍插件之前让我们先回退到上一个版本,我们 ...

  4. TienChin 活动管理-修改活动

    后端 ChannelController.java @PreAuthorize("hasPermission('tienchin:channel:edit')") @GetMapp ...

  5. TienChin 引入 MyBatisPlus

    在父工程当中添加版本号,统一管理: <mybatis-plus.version>3.5.1</mybatis-plus.version> 在父工程当中添加 MyBatisPlu ...

  6. 5.1 C/C++ 使用文件与指针

    C/C++语言是一种通用的编程语言,具有高效.灵活和可移植等特点.C语言主要用于系统编程,如操作系统.编译器.数据库等:C语言是C语言的扩展,增加了面向对象编程的特性,适用于大型软件系统.图形用户界面 ...

  7. x64dbg 2022 最新版编译方法

    x64dbg 调试器的源码编译很麻烦,网络上的编译方法均为老版本,对于新版本来说编译过程中会出现各种错误,编译的坑可以说是一个接着一个,本人通过研究总结出了一套编译拳法可以完美编译输出,不过话说回来x ...

  8. Centos7 本地与网络Yum源配置

    虽然Yum工具,只需要你的主机连接互联网,就可以直接使用,但是有些时候我们需要自定义Yum源实现加速,下面我们将配置一个本地Yum源,来使用光盘中的软件,其他网络配置操作步骤相同,只是会在baseur ...

  9. idea2018 破解

    本人使用的是idea2018.1.11,对2018其它版本的应该都是管用的 idea2018-1.11 下载地址 链接:https://pan.baidu.com/s/1_RlJGZtfMxr1Nx9 ...

  10. Firefox浏览器的一些配置

    一.在新标签页打开书签 1.打开Firefox浏览器,地址栏输入about:config. 2.选择"接受风险并继续". 3.搜索browser.tabs.loadBookmark ...