之前把web实现了docker,开发或测试环境可能需要开发自己搭数据库,为了方便使用,把数据库也做一个docker。
由于原生的CentOS我还有改yum仓库,所以这次从之前lis搞的改好yum的镜像开始(从改好yum的lisnew的镜像创建lisdb容器,IRIS安装包依赖了一个gzip包,懒得找离线包了)
docker run -idt -p 1972:1972-p 52773:52773--name=lisdb -v /dthealth/db/dthis:/dthealth/db/dthis lisnew
然后启动容器并进入容器,上传IRIS安装包安装数据库
[root@localhost /]# docker start lisdb
lisdb
[root@localhost /]# docker exec -it lisdb /bin/bash
[root@a3f4f856634b /]# ls
bin boot centos8 dev dthealth etc home intersystem lib lib64 lost+found media mnt opt proc root run sbin srv start.sh sys testdraw tmp usr var
[root@a3f4f856634b /]#
解压安装包-授权执行权限然后按照提示安装数据库
cd /dthealth/db/dthis/
tar -xvf IRISHealth-2021.1.2.338.0.21956-lnxrhx64.tar.gz
cd IRISHealth-2021.1.2.338.0.21956-lnxrhx64
chmod +x irisinstall
./irisinstall
安装完之后把数据库iris.cpf移动到/dthealth/db/dthis/下,后面方便用目录映射到外面调整cpf
在容器的/下新建一个start.sh文件来启动数据库,不通过这个脚本转一下来启动数据库,启动由于没阻塞容器里面又关闭了,所以启动数据库后tail让sh阻塞
#!/bin/bash
# 启动数据库
iris start IRISHEALTH
# 此处是为了运行完上条应用服务后,有对应的前台进程
tail -f /dev/null
把修改生成新的镜像lisdb
docker commit -a "zhanglianzhu" -m "lisdb9.0" lisdb lisdb:9.2
制作Dockerfile文件
#构造数据库的docker镜像
#基础镜像
FROM lisdb:9.2 AS base
#MAINTAINER 维护者信息
MAINTAINER zhanglianzhu
#工作路径
WORKDIR /
#对外端口
EXPOSE 1972
EXPOSE 52773
#映射路径
VOLUME ["/dthealth/db/dthis"]
VOLUME ["/intersystem/iris.cpf"]
#启动容器执行的命令
ENTRYPOINT ["/bin/bash", "/start.sh"]
制作镜像(把Dockerfile上传到/zlzdocker)
cd /zlzdocker
docker build -t lisdb:9.0 .
压缩导出镜像即可
docker save lisdb:9.0 | gzip > lisdb.tar.gz
镜像测试,同时映射db的文件目录和cpf文件目录,db文件和cpf文件配置对上即可
gunzip -c /zlzdocker/lisdb.tar.gz | docker load
docker run -idt -p 1972:1972 -p 52773:52773 --name=lisdb -v /dthealth/db/dthis:/dthealth/db/dthis -v /dthealth/db/dthis/iris.cpf:/intersystem/iris.cpf lisdb:9.3
docker start lisdb
进入容器查看和测试
[root@localhost /]# docker exec -it lisdb /bin/bash
[root@a3f4f856634b /]# ls
bin boot centos8 dev dthealth etc home intersystem lib lib64 lost+found media mnt opt proc root run sbin srv start.sh sys testdraw tmp usr var
[root@a3f4f856634b /]#
[root@a3f4f856634b /]#
[root@a3f4f856634b /]#
[root@a3f4f856634b /]#
[root@a3f4f856634b /]#
[root@a3f4f856634b /]# iris list
Configuration 'IRISHEALTH' (default)
directory: /intersystem
versionid: 2021.1.2.338.0.21956
datadir: /intersystem
conf file: iris.cpf (SuperServer port = 1972, WebServer = 52773)
status: running, since Tue Jul 25 08:40:22 2023
state: ok
product: InterSystems IRISHealth
[root@a3f4f856634b /]#
面向开发的一键部署web和db脚本命令
#!/bin/bash
#shell检验基础维护脚本-用容器构造lis程序。开发使用,会同时构造数据库和web
#20220721
#zlz
#----------------------------------------------------------
#第一次执行:bash /dthealth/app/dthis/imedicallis/docker/lisdevinit.sh
#非第一次执行:lis或lisdocker
if [ ! -f /usr/bin/lisdocker ];then
echo "安装imedicallis命令,后面通过imedicallis驱动"
cp /dthealth/app/dthis/imedicallis/docker/lisdocker /usr/bin/
chmod 777 /usr/bin/lisdocker
ln -s /usr/bin/lisdocker /usr/bin/lis
fi
echo "+要求先安装好docker软件"
echo "+该脚本将为你用检验docker镜像构造检验容器"
echo "+解压和载入镜像文件"
gunzip -c /dthealth/app/dthis/imedicallis/docker/lisdocker.tar.gz | docker load
echo "+查看镜像"
docker images
echo "+构造名称为lisdocker的检验容器"
docker run -idt -p 5002:5002 -p 8081:8081 --name=lisdocker -v /dthealth/app/dthis/imedicallis:/dthealth/app/dthis/imedicallis lisdocker:latest
echo "+启动检验容器"
docker start lisdocker
echo "+用容器部署检验完成"
echo "+进入容器请运行lis或者lisdocker命令"
echo "+解压和载入镜像文件"
gunzip -c /dthealth/app/dthis/imedicallis/docker/lisdb.tar.gz | docker load
echo "+查看镜像"
docker images
echo "+构造名称为lisdb的检验容器"
docker run -idt -p 1972:1972 -p 52773:52773 --name=lisdb -v /dthealth/db/dthis:/dthealth/db/dthis -v /dthealth/db/dthis/iris.cpf:/intersystem/iris.cpf lisdb:9.3
echo "+启动db容器"
docker start lisdb
echo "+用容器部署检验数据库完成"
echo "+"
commit之后会导致镜像越来越大,可以先把镜像export后再import来去除多层减少大小,import之后的镜像丢失了Dockerfile的ENTRYPOINT,需要用Dockerfile再重建一下,否则启动没执行命令
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
lisdocker latest 3e84e2582c4a 5 days ago 1.63GB
[root@localhost ~]# cd /zlzdocker/
[root@localhost zlzdocker]# docker export -o img.tar 3e84e2582c4a
Error response from daemon: No such container: 3e84e2582c4a
[root@localhost zlzdocker]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
84cac323a25f lisdocker:latest "dotnet /dthealth/ap…" 5 minutes ago Up 5 minutes 0.0.0.0:5002->5002/tcp, :::5002->5002/tcp, 0.0.0.0:8081->8081/tcp, :::8081->8081/tcp lisdocker
[root@localhost zlzdocker]# docker export -o img.tar 84cac323a25f
[root@localhost zlzdocker]# docker import img.tar lisdocker:9.5
sha256:4ad978e289bc755ba3f82175e7e5e1f18ed06b073903e5a5ed47e2a5a78590d0
[root@localhost zlzdocker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
lisdocker 9.5 4ad978e289bc 8 seconds ago 1.09GB
lisdb 9.3 7a89c2c84a7c 39 minutes ago 13.8GB
lisdocker latest 3e84e2582c4a 5 days ago 1.63GB
[root@localhost zlzdocker]# docker save lisdocker:9.5 | gzip > lisdocker.tar.gz
[root@localhost zlzdocker]# docker export -o img1.tar ae1f63b9cf12
[root@localhost zlzdocker]# docker import img1.tar lisdb:9.5
sha256:78e860c142761e199958edcc7305219fd4d62879b28fe17716e0b13aaa7d382c
[root@localhost zlzdocker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
lisdb 9.5 78e860c14276 44 seconds ago 3.99GB
lisdocker 9.5 4ad978e289bc 7 minutes ago 1.09GB
lisdb 9.3 7a89c2c84a7c 46 minutes ago 13.8GB
lisdocker latest 3e84e2582c4a 5 days ago 1.63GB
[root@localhost zlzdocker]# docker save lisdb:9.5 | gzip > lisdb.tar.gz