制作一个Dockerfile,在镜像中启动应用
Dockerfile为
点击查看代码
FROM iot-service:first
ADD xx-weiba-1.0.0.jar /usr/local/
EXPOSE 8080
ADD setenv.sh /usr/local/bin
ADD startup.sh /usr/local/bin
RUN chmod a+x /usr/local/bin/*.sh
ENV LANG=zh_CN.UTF-8
CMD [ "startup.sh" , "run" ]
#ENTRYPOINT java -jar -Xms4096m -Xmx4096m -XX:PermSize=1024m -XX:MaxPermSize=2048m /usr/local/xxxx-weiba-1.0.0.jar
startup.sh为:
点击查看代码
#!/bin/bash
cd /usr/local || exit 111
[ -f "xxxx-weiba-1.0.0.jar" ] || exit 111
[ -f "bin/setenv.sh" ] || exit 111
export LANG=GBK
# get application.yml file
jar xf xxxx-weiba-1.0.0.ja BOOT-INF/classes/application.yml
# modify configure
setenv.sh
#
jar uf0 xxxx-weiba-1.0.0.ja BOOT-INF/classes/application.yml
# running this jar
java -Xms6000m -Xmx6000m -XX:MetaspaceSize=1024m -XX:MaxMetaspaceSize=2048m -jar xxxx-weiba-1.0.0.ja
#sleep 120
setenv.sh内容为:
点击查看代码
#!/bin/bash
# iot修改
redis_host=`echo $redis_nodes|awk -F ':' '{print $2}'`
redis_port=`echo $redis_nodes|awk -F ':' '{print $3}'`
sed -i 's# port: .*# port: 8080#g' /usr/local/BOOT-INF/classes/application.yml
# 存在这个值才替换
[ ! -z "$nacos_host" ] && sed -i 's#server-addr:.*#server-addr: '"${nacos_host}"'#g' /usr/local/BOOT-INF/classes/application.yml
sed -i 's#host: tcp://.*#host: tcp://'"${mqtt_host}"'#g' /usr/local/BOOT-INF/classes/application.yml
sed -i 's#client-id:.*#client-id: '"${mqtt_clientid}"'#g' /usr/local/BOOT-INF/classes/application.yml
# 现场暂时不用配置,先注释掉
#sed -i 's#redishost: .*#redishost: '"${redis_host}"'#g' /usr/local/BOOT-INF/classes/application.yml
#sed -i 's#redisport: .*#redisport: '"${redis_port}"'#g' /usr/local/BOOT-INF/classes/application.yml
#sed -i 's#redispassword: .*#redispassword: \"'"${redis_password}"'\"#g' /usr/local/BOOT-INF/classes/application.yml
sed -i 's#^ host: http://.*# host: http://'"${gate_host}"'#g' /usr/local/BOOT-INF/classes/application.yml
sed -i 's#jkzdhostOline: http://.*/saveOnLine#jkzdhostOline: http://'"${huairen_host}"'/saveOnLine#g' /usr/local/BOOT-INF/classes/application.yml
sed -i 's#^ jkzdhost: http://.*/web/conditionMmonitoringAction/dynamicInsert# jkzdhost: http://'"${huairen_host}"'/web/conditionMmonitoringAction/dynamicInsert#g' /usr/local/BOOT-INF/classes/application.yml
sed -i 's#jkzdhosts: http://.*/web/conditionMmonitoringAction/initDeviceInfo#jkzdhosts: http://'"${huairen_host}"'/web/conditionMmonitoringAction/initDeviceInfo#g' /usr/local/BOOT-INF/classes/application.yml
docker build -f Dockerfile -t xxx-weiba-service:latest .
docker run -it --rm --name xxx-weiba-service -h xxx-weiba-service -p 33333:8080 -e sproc_host=10.88.17.200:30001 -e nacos_host=192.168.160.4:26061 -e mqtt_host=192.168.216.1:32747 -e gate_host=192.168.216.1:30083 --privileged=true xxx-weiba-service:latest