Docker 发布的方式为实现DevOps(自动化运维,需要配置 代码管理工具如Git的hook来实现提交编译、打包、发布等一系列事件控制)提供了诸多方便,辅助于Shell脚本可以很好的配合起来。
Docker镜像可以通过自动化编译,也可以通过导入镜像的方式来获得。
本文的题目叫:Shell脚本构建Docker 半自动化编译打包发布,因为我这里还没跟代码管理关联起来。
Shell脚本不同实现
导入镜像方式(镜像文件rtvsweb-publish.tar):
构建发布方式(依靠Dockerfile来构建):
Shell Docker构建发布脚本工具核心install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
|
#! /bin/bash ##file:rtvs.sh ##company:cvnavi.com ##author:Pengjunlin echo "当前执行文件......$0" ##################################变量定义################################## DOCKER_IMAGE_IS_MATCH_TAR_FILE= "false" DOCKER_RTVSWEB_CONTAINER_NAME= "rtvsweb-publish" DOCKER_RTVSWEB_NEW_VERSION= "" DOCKER_RTVSWEB_FIRST_VERSION=1 DOCKER_RTVSWEB_SECOND_VERSION=0 DOCKER_RTVSWEB_THIRD_VERSION=0 DOCKER_RTVSWEB_VERSION_TAG= "" DOCKER_CONTAINER_TEMP_HOST= "" DB_REDIS_CONNECTION_STRING= "" DB_MYSQL_CONNECTION_STRING= "" DB_MYSQL_HOST= "" MASTER_LAN_IP= "" SYSTEM_ALLOW_TO_SET= "false" ###################################函数定义####################################### function init_files() { # 创建rtvs目录 if [[ ! -d "/usr/local/rtvs" ]]; then echo "创建容器映射路径.... /usr/local/rtvs" mkdir /usr/local/rtvs fi # 复制VersionConfig.xml(第一次做完全复制,若有变动需要手动修改) if [[ -f "./VersionConfig.xml" ]]; then if [[ ! -f "/usr/local/rtvs/VersionConfig.xml" ]]; then echo "拷贝一份XML配置文件: ./VersionConfig.xml /usr/local/rtvs/VersionConfig.xml" cp VersionConfig.xml /usr/local/rtvs/VersionConfig .xml fi else echo "缺少./VersionConfig.xml文件...已退出安装!" exit fi # 复制SettingConfig.xml(第一次做完全复制,若有变动需要手动修改) if [[ -f "./SettingConfig.xml" ]]; then if [[ ! -f "/usr/local/rtvs/SettingConfig.xml" ]]; then echo "拷贝一份XML配置文件: ./SettingConfig.xml /usr/local/rtvs/SettingConfig.xml" cp SettingConfig.xml /usr/local/rtvs/SettingConfig .xml fi else echo "缺少./SettingConfig.xml文件...已退出安装!" exit fi # 复制log4.config(第一次做完全复制,若有变动需要手动修改) if [[ -f "./log4.config" ]]; then if [[ ! -f "/usr/local/rtvs/log4.config" ]]; then echo "拷贝一份日志配置文件: ./log4.config /usr/local/rtvs/log4.config" cp log4.config /usr/local/rtvs/log4 .config fi else echo "缺少./log4.config文件...已退出安装!" exit fi } function mysql_create_table() { if [[ -f "./mysql_create_table.sh" ]]; then echo "数据库脚本赋值权限......" # 为执行文件添加权限 chmod a+x mysql_create_table.sh else echo "缺少./mysql_create_table.sh文件...已退出安装!" exit fi # 执行mysql数据库表创建 . /mysql_create_table .sh if [[ $? - eq 0 ]]; then echo "./mysql_docker_install.sh 执行完成!" else exit fi } function docker_install() { echo "检查Docker......" docker - v if [ $? - eq 0 ]; then echo "检查到Docker已安装!" else echo "安装docker环境..." curl -sSL https: //get .daocloud.io /docker | sh echo "安装docker环境...安装完成!" fi # 创建公用网络==bridge模式 #docker network create share_network } function mysql_install(){ install_type=$1 if [[ "$install_type" == "by_local_mysql_installer" ]]; then #statements echo "暂不支持wget本地下载安装,已退出!" exit 1 fi if [[ "$install_type" == "by_docker_mysql_installer" ]]; then #statements docker_mysql_install fi if [[ "$install_type" == "by_smart_installer" ]]; then #statements if [[ ` netstat -lanp| grep tcp| grep 3306| wc -l` == 1 ]]; then echo "检测到mysql已在本机安装!" # 打印一下mysql版本 echo "检测到mysql版本:" mysql --version # 执行创建Mysql数据库脚本 mysql_create_table if [[ $? - eq 0 ]]; then echo "本地MySQL脚本初始化完成!" else echo "本地MySQL脚本初始化失败!" exit 1 fi DB_MYSQL_HOST= "localhost" else docker_mysql_install fi fi } function docker_mysql_install(){ echo "安装Docker Mysql环境..." if [[ -f "./docker_mysql_install.sh" ]]; then if [[ -f "./docker_mysql_create_table.sh" ]]; then echo "拷贝一份容器执行文件: ./docker_mysql_create_table.sh /usr/local/docker_mysql_create_table.sh" cp docker_mysql_create_table.sh /usr/local/docker_mysql_create_table .sh else echo "缺少./docker_mysql_create_table.sh文件...已退出安装!" exit 1 fi # 为执行文件添加权限 chmod a+x docker_mysql_install.sh # Dokcer方式安装Mysql . /docker_mysql_install .sh if [[ $? - eq 0 ]]; then echo "./docker_mysql_install.sh 执行完成!" # 休10秒钟 echo "休眠等待10s,等待Docker执行完成......" sleep 10s # 测试打印mysql信息 print_docker_mysql_info else echo "./docker_mysql_install.sh 执行过程中出现错误,已退出安装!" exit 1 fi else echo "缺少./docker_mysql_install.sh文件...已退出安装!" exit 1 fi } function docker_container_ip() { DOCKER_CONTAINER_TEMP_HOST=` docker inspect -- format '{{ .NetworkSettings.IPAddress }}' $1` } function init_docker_master_ip(){ out=0 for i in `ip a | grep inet[^6]| grep -E -o '([0-9]{1,3}\.){3}[0-9]{1,3}' `; do OLD_IFS= "$IFS" IFS= "." arr=($i) IFS= "$OLD_IFS" for s in ${arr[@]} ; do if [[ $s - eq "192" ]]; then echo "$i" MASTER_LAN_IP=$i out=1 break fi done if [[ $out - eq 1 ]]; then break fi done } function print_docker_mysql_info() { echo "脚本执行Mysql信息验证:..." if [[ -f "./docker_mysql_validator.sh" ]]; then echo "拷贝一份容器执行文件: ./docker_mysql_validator.sh /usr/local/docker_mysql_validator.sh" cp docker_mysql_validator.sh /usr/local/docker_mysql_validator .sh else echo "缺少./docker_mysql_validator.sh文件...已退出安装!" exit fi # 映射copy文件路径到docker容器 docker cp /usr/local/docker_mysql_validator .sh mysql5.7: /usr/local/docker_mysql_validator .sh docker exec -it mysql5.7 /bin/bash -c "sh /usr/local/docker_mysql_validator.sh" if [[ $? - eq 0 ]]; then echo "./docker_mysql_validator.sh 执行完成!" echo "MySQL容器Host:" docker_container_ip mysql5.7 echo "当前mysql5.7实例IP=$DOCKER_CONTAINER_TEMP_HOST" #echo "MySQL容器network 相关信息:" #docker network inspect share_network #echo "MySQL容器link相关信息:" #cat /etc/hosts else echo "./docker_mysql_validator.sh 执行过程中出现错误,已退出安装!" exit fi #link 访问方式 DB_MYSQL_HOST= "mysql5.7" } function destory_docker_service() { # 停止容器 for i in [ `docker ps ` ]; do if [[ "$i" == "rtvsweb-publish" ]]; then echo "尝试停止$DOCKER_RTVSWEB_CONTAINER_NAME容器..." docker stop $DOCKER_RTVSWEB_CONTAINER_NAME fi done # 删除容器 for i in [ `docker ps -a` ]; do if [[ "$i" == "rtvsweb-publish" ]]; then echo "尝试删除$DOCKER_RTVSWEB_CONTAINER_NAME容器..." docker rm $DOCKER_RTVSWEB_CONTAINER_NAME fi done } function docker_build_image() { # 清理容器(保留历史构建的镜像) destory_docker_service if [[ $? - eq 0 ]]; then echo "应用服务容器和镜像已处理,配置文件已完成复制!" else exit 1 fi echo "Docker镜像构建......cmd:(docker build -t rtvsweb:$DOCKER_RTVSWEB_NEW_VERSION .)" docker build -t rtvsweb:$DOCKER_RTVSWEB_NEW_VERSION . # 判断是否有镜像,存在时创建相应的容器实例 for i in [ `docker images` ]; do #statements if [[ "$i" == "$DOCKER_RTVSWEB_NEW_VERSION" ]]; then DOCKER_IMAGE_IS_MATCH_TAR_FILE= "true" echo "已经找到最新构建的镜像!" run_docker_service_image break fi done if [[ $DOCKER_IMAGE_IS_MATCH_TAR_FILE == "false" ]]; then echo "构建镜像未匹配到最新版本,已退出安装!" exit 1 fi echo "构建后的docker images镜像列表:" docker images echo "当前正在运行的Docker容器实例列表:" docker ps } function run_docker_service_image() { echo "正在启动docker 服务容器......" # run 的参数设置参考VS项目启动的设置--privileged=true 获取管理员权限 # ===bridge 桥接模式 #docker run -it --name=$DOCKER_RTVSWEB_CONTAINER_NAME --net="bridge" --dns 8.8.8.8 --network share_network --network-alias $4 -v /usr/local/rtvs/error_log:/app/Error_log -v /usr/local/rtvs/log_file:/app/LogFile -v /usr/local/rtvs/mydata:/MyData -v /usr/local/rtvs/videocache:/MyVideo -v /usr/local/rtvs/SettingConfig.xml:/app/SettingConfig.xml -p 38067:80 -p 44383:443 -p 18000:18000 -p 18002:18002 -p 19700:19700 -p 19702:19702 -p 19703:19703 -d $DOCKER_RTVSWEB_IMAGE_TAG_NAME if [[ $DB_MYSQL_HOST == "mysql5.7" ]]; then # ===link 链接模式 echo "rtvsweb--容器运行---链接模式" docker run -it --name $DOCKER_RTVSWEB_CONTAINER_NAME --privileged= true --link mysql5.7:mysql5.7 - v /usr/local/rtvs : /MyData -e MyDataPath= /MyData -p 38067:80 -p 44383:443 -p 18000:18000 -p 18002:18002 -p 19700-19719:19700-19719 -p 30888-30889:30888-30889 -d rtvsweb:$DOCKER_RTVSWEB_NEW_VERSION else # ===普通模式 echo "rtvsweb--容器运行---普通模式" docker run -it --name $DOCKER_RTVSWEB_CONTAINER_NAME --privileged= true - v /usr/local/rtvs : /MyData -e MyDataPath= /MyData -p 38067:80 -p 44383:443 -p 18000:18000 -p 18002:18002 -p 19700-19719:19700-19719 -p 30888-30889:30888-30889 -d rtvsweb:$DOCKER_RTVSWEB_NEW_VERSION fi } ####################工具类和流程定制################################ function editXml() { val=` echo ${@:3}` echo "正在修改XML文件:$1...." echo "正在修改XML文件:[0]=$1,[1]=$2,[2]=$val" echo "XML文件$2标签 value=$val" sed -i "s/<$2>.*<\/$2>/<$2>${val}<\/$2></g" $1 } function init_mysql_conn() { if [[ "$DB_MYSQL_HOST" == "localhost" ]]; then mysql= "Database=filecache;Data Source=$MASTER_LAN_IP;port=3366;User Id=rtvsweb;Password=rtvs2018;charset=utf8;pooling=true" sed -i "s/<MysqlConnectionString>.*<\/MysqlConnectionString>/<MysqlConnectionString>$mysql<\/MysqlConnectionString>/g" /usr/local/rtvs/SettingConfig .xml DB_MYSQL_CONNECTION_STRING=` grep -E -o -e '<MysqlConnectionString>.+</MysqlConnectionString>' /usr/local/rtvs/SettingConfig .xml | sed 's/<MysqlConnectionString>//g' | sed 's/<\/MysqlConnectionString>//g' ` else mysql= "Database=filecache;Data Source=mysql5.7;port=3306;User Id=rtvsweb;Password=rtvs2018;charset=utf8;pooling=true" sed -i "s/<MysqlConnectionString>.*<\/MysqlConnectionString>/<MysqlConnectionString>$mysql<\/MysqlConnectionString>/g" /usr/local/rtvs/SettingConfig .xml DB_MYSQL_CONNECTION_STRING=` grep -E -o -e '<MysqlConnectionString>.+</MysqlConnectionString>' /usr/local/rtvs/SettingConfig .xml | sed 's/<MysqlConnectionString>//g' | sed 's/<\/MysqlConnectionString>//g' ` fi } function editSpecificConfig() { init_mysql_conn echo "获取/usr/local/rtvs/SettingConfig.xml信息..." cat /usr/local/rtvs/SettingConfig .xml # 判断是否可以设置 if [[ "$SYSTEM_ALLOW_TO_SET" == "true" ]]; then read -p ">>>是否修改Redis配置连接字符串?y/n:" ans echo "$ans" if [[ "$ans" == "y" ]]; then read -p "请输入Redis配置连接字符串:" redis echo "新的Redis连接字符串:$redis" sed -i "s/<RedisExchangeHosts>.*<\/RedisExchangeHosts>/<RedisExchangeHosts>$redis<\/RedisExchangeHosts>/g" /usr/local/rtvs/SettingConfig .xml DB_REDIS_CONNECTION_STRING=` grep -E -o -e '<RedisExchangeHosts>.+</RedisExchangeHosts>' /usr/local/rtvs/SettingConfig .xml | sed 's/<RedisExchangeHosts>//g' | sed 's/<\/RedisExchangeHosts>//g' ` echo "获取已修改的Redis配置连接字符串...RedisExchangeHosts=$DB_REDIS_CONNECTION_STRING" fi read -p ">>>是否修改Mysql配置连接字符串?y/n:" ans echo "$ans" if [[ "$ans" == "y" ]]; then read -p "请输入Mysql配置连接字符串:" mysql echo "新的Mysql连接字符串:$mysql" sed -i "s/<MysqlConnectionString>.*<\/MysqlConnectionString>/<MysqlConnectionString>$mysql<\/MysqlConnectionString>/g" /usr/local/rtvs/SettingConfig .xml DB_MYSQL_CONNECTION_STRING=` grep -E -o -e '<MysqlConnectionString>.+</MysqlConnectionString>' /usr/local/rtvs/SettingConfig .xml | sed 's/<MysqlConnectionString>//g' | sed 's/<\/MysqlConnectionString>//g' ` echo "获取已修改的Mysql配置连接字符串...MysqlConnectionString=$DB_MYSQL_CONNECTION_STRING" fi fi } function remoteRedisAndMysqlConfig() { echo "获取/usr/local/rtvs/SettingConfig.xml信息..." cat /usr/local/rtvs/SettingConfig .xml # 设置Redis连接字符串 read -p "是否修改Redis配置连接字符串?y/n:" ans echo "$ans" if [[ "$ans" == "y" ]]; then read -p "请输入Redis连接字符串:" redis echo "新的Redis连接字符串:$redis" sed -i "s/<RedisExchangeHosts>.*<\/RedisExchangeHosts>/<RedisExchangeHosts>$redis<\/RedisExchangeHosts>/g" /usr/local/rtvs/SettingConfig .xml DB_REDIS_CONNECTION_STRING=` grep -E -o -e '<RedisExchangeHosts>.+</RedisExchangeHosts>' /usr/local/rtvs/SettingConfig .xml | sed 's/<RedisExchangeHosts>//g' | sed 's/<\/RedisExchangeHosts>//g' ` echo "获取已修改的Redis配置连接字符串...RedisExchangeHosts=$DB_REDIS_CONNECTION_STRING" fi read -p "是否修改Mysql配置连接字符串?y/n:" ans echo "$ans" if [[ "$ans" == "y" ]]; then read -p "请输入Mysql连接字符串:" mysql echo "新的Mysql连接字符串:$mysql" sed -i "s/<MysqlConnectionString>.*<\/MysqlConnectionString>/<MysqlConnectionString>$mysql<\/MysqlConnectionString>/g" /usr/local/rtvs/SettingConfig .xml DB_MYSQL_CONNECTION_STRING=` grep -E -o -e '<MysqlConnectionString>.+</MysqlConnectionString>' /usr/local/rtvs/SettingConfig .xml | sed 's/<MysqlConnectionString>//g' | sed 's/<\/MysqlConnectionString>//g' ` echo "获取已修改的Mysql配置连接字符串...MysqlConnectionString=$DB_MYSQL_CONNECTION_STRING" fi } function help() { echo "*******************************************" echo "********* 调用方法说明 ************" echo "*******************************************" echo "查看核心配置文件:cat ./SettingConfig.xml" echo "帮助方法说明:sh ./install.sh help" echo "修改Redis和MySQL连接字符串:sh ./install.sh editXml [XMLFilePath] [tag] ['value'] " echo "********************************************" echo "********* 快速定制安装 *************" echo "********************************************" echo "1、执行本地Mysql安装(wget下载文件安装...比较费时): sh ./install.sh by_local_mysql_installer" echo "2、执行Docker Mysql安装 : sh ./install.sh by_docker_mysql_installer" echo "3、智能检测决定Mysql安装方式(如果本机已有MySQL则直接使用): sh ./install.sh by_smart_installer" echo "4、简化安装只需要给出Redis和MySQL连接字符串即可(极简方式): sh ./install.sh by_simple_installer" echo "说明:\r 以上4种方式已包含了Docker应用的安装!" } function completed() { echo "******************安装结果:*****************" # bridge 桥接模式 #echo "network实例, share_network相关容器信息:" #docker network inspect share_network version_step=1 # 记录下一次版本号 if [[ "$DOCKER_RTVSWEB_VERSION_TAG" == "VersionFirst" ]]; then DOCKER_RTVSWEB_FIRST_VERSION=$((DOCKER_RTVSWEB_FIRST_VERSION+version_step)) sed -i "s/<VersionFirst>.*<\/VersionFirst>/<VersionFirst>$DOCKER_RTVSWEB_FIRST_VERSION<\/VersionFirst>/g" /usr/local/rtvs/VersionConfig .xml sed -i "s/<VersionSecond>.*<\/VersionSecond>/<VersionSecond>0<\/VersionSecond>/g" /usr/local/rtvs/VersionConfig .xml sed -i "s/<VersionThird>.*<\/VersionThird>/<VersionThird>0<\/VersionThird>/g" /usr/local/rtvs/VersionConfig .xml fi if [[ "$DOCKER_RTVSWEB_VERSION_TAG" == "VersionSecond" ]]; then DOCKER_RTVSWEB_SECOND_VERSION=$((DOCKER_RTVSWEB_SECOND_VERSION+version_step)) sed -i "s/<VersionSecond>.*<\/VersionSecond>/<VersionSecond>$DOCKER_RTVSWEB_SECOND_VERSION<\/VersionSecond>/g" /usr/local/rtvs/VersionConfig .xml sed -i "s/<VersionThird>.*<\/VersionThird>/<VersionThird>0<\/VersionThird>/g" /usr/local/rtvs/VersionConfig .xml fi if [[ "$DOCKER_RTVSWEB_VERSION_TAG" == "VersionThird" ]]; then DOCKER_RTVSWEB_THIRD_VERSION=$((DOCKER_RTVSWEB_THIRD_VERSION+version_step)) sed -i "s/<VersionThird>.*<\/VersionThird>/<VersionThird>$DOCKER_RTVSWEB_THIRD_VERSION<\/VersionThird>/g" /usr/local/rtvs/VersionConfig .xml fi VIDEO_CACHE_PATH=` grep -E -o -e '<VideoCachePath>.+</VideoCachePath>' /usr/local/rtvs/SettingConfig .xml | sed 's/<VideoCachePath>//g' | sed 's/<\/VideoCachePath>//g' ` DB_REDIS_CONNECTION_STRING=` grep -E -o -e '<RedisExchangeHosts>.+</RedisExchangeHosts>' /usr/local/rtvs/SettingConfig .xml | sed 's/<RedisExchangeHosts>//g' | sed 's/<\/RedisExchangeHosts>//g' ` DB_MYSQL_CONNECTION_STRING=` grep -E -o -e '<MysqlConnectionString>.+</MysqlConnectionString>' /usr/local/rtvs/SettingConfig .xml | sed 's/<MysqlConnectionString>//g' | sed 's/<\/MysqlConnectionString>//g' ` echo "Redis连接字符串:$DB_REDIS_CONNECTION_STRING" echo "Mysql连接字符串:$DB_MYSQL_CONNECTION_STRING" echo "默认视频缓存目录:$VIDEO_CACHE_PATH" echo "正在运行的容器实例:" docker ps echo "容器对应的Ip地址:" docker_container_ip mysql5.7 if [[ "$DOCKER_CONTAINER_TEMP_HOST" != "" ]]; then echo "mysql5.7 ---------------------$DOCKER_CONTAINER_TEMP_HOST" fi docker_container_ip $DOCKER_RTVSWEB_CONTAINER_NAME echo "$DOCKER_RTVSWEB_CONTAINER_NAME ---------------------$DOCKER_CONTAINER_TEMP_HOST" echo "验证rtvs访问:curl http://cvtsp.com:38067/" echo "******************安装完成!*****************" } function version_management() { DOCKER_RTVSWEB_FIRST_VERSION=` grep -E -o -e '<VersionFirst>.+</VersionFirst>' /usr/local/rtvs/VersionConfig .xml | sed 's/<VersionFirst>//g' | sed 's/<\/VersionFirst>//g' ` DOCKER_RTVSWEB_SECOND_VERSION=` grep -E -o -e '<VersionSecond>.+</VersionSecond>' /usr/local/rtvs/VersionConfig .xml | sed 's/<VersionSecond>//g' | sed 's/<\/VersionSecond>//g' ` DOCKER_RTVSWEB_THIRD_VERSION=` grep -E -o -e '<VersionThird>.+</VersionThird>' /usr/local/rtvs/VersionConfig .xml | sed 's/<VersionThird>//g' | sed 's/<\/VersionThird>//g' ` DOCKER_RTVSWEB_VERSION_TAG=` grep -E -o -e '<UpgradeTag>.+</UpgradeTag>' /usr/local/rtvs/VersionConfig .xml | sed 's/<UpgradeTag>//g' | sed 's/<\/UpgradeTag>//g' ` DOCKER_RTVSWEB_NEW_VERSION= "$DOCKER_RTVSWEB_FIRST_VERSION.$DOCKER_RTVSWEB_SECOND_VERSION.$DOCKER_RTVSWEB_THIRD_VERSION" echo "当前rtvsweb版本:$DOCKER_RTVSWEB_NEW_VERSION" echo "当前rtvsweb版本升级格式:$DOCKER_RTVSWEB_VERSION_TAG" } function by_local_mysql_installer() { # Docker 安装 docker_install # Mysql 安装及其脚本创建 mysql_install "by_local_mysql_installer" # 镜像构建 if [[ $? - eq 0 ]]; then docker_build_image if [[ $? - eq 0 ]]; then echo "镜像构建成功!" else echo "镜像构建失败!" exit fi else exit fi # 修改镜像使用的路径和数据源 editSpecificConfig # 完成后输出 completed } function by_docker_mysql_installer() { # Docker 安装 docker_install # Mysql 安装及其脚本创建 mysql_install "by_docker_mysql_installer" # 镜像构建 if [[ $? - eq 0 ]]; then docker_build_image if [[ $? - eq 0 ]]; then echo "镜像构建成功!" else echo "镜像构建失败!" exit fi else exit fi # 修改镜像使用的路径和数据源 editSpecificConfig # 完成后输出 completed } function by_smart_installer() { # Docker 安装 docker_install # Mysql 安装及其脚本创建 mysql_install "by_smart_installer" # 镜像构建 if [[ $? - eq 0 ]]; then docker_build_image if [[ $? - eq 0 ]]; then echo "镜像构建成功!" else echo "镜像构建失败!" exit fi else exit fi # 修改镜像使用的路径和数据源 editSpecificConfig # 完成后输出 completed } function by_simple_installer() { # Docker 安装 docker_install # 镜像构建 docker_build_image if [[ $? - eq 0 ]]; then echo "镜像构建成功!" else echo "镜像构建失败!" exit fi # 修改镜像使用的路径和数据源 remoteRedisAndMysqlConfig # 完成后输出 completed } if [[ $ # -gt 0 ]]; then echo "安装所需文件检查...." init_files if [[ $? - eq 0 ]]; then echo "安装Docker服务的文件存在,验证通过!" else echo "安装Docker服务的文件存在缺失,已退出安装!" exit fi echo "rtvsweb版本检查...." version_management echo "获取本地局域网IP地址...." init_docker_master_ip echo "本地IP地址....MASTER_LAN_IP=$MASTER_LAN_IP" #statements if [[ "$1" == "by_local_mysql_installer" ]]; then #statements by_local_mysql_installer fi if [[ "$1" == "by_docker_mysql_installer" ]]; then #statements by_docker_mysql_installer fi if [[ "$1" == "by_smart_installer" ]]; then #statements by_smart_installer fi if [[ "$1" == "by_simple_installer" ]]; then #statements by_simple_installer fi if [[ "$1" == "editXml" ]]; then if [[ $ # -eq 4 ]]; then #statements editXml $2 $3 $4 else echo "editXml参数个数不匹配!" fi fi if [[ "$1" == "help" ]]; then #statements help fi else help fi |
整体设计实现思路
1、Docker环境准备和安装
2、MySQL环境准备和安装
3、Docker的知识:构建、运行
4、Docker镜像的版本管理
5、容期间网络访问:--link
6、镜像打包历史
7、服务运行效果
以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。如有错误或未考虑完全的地方,望不吝赐教。
原文链接:https://blog.csdn.net/boonya/article/details/83383437