概述
将Springboot的web服务打包成Jar包后,自动化脚本将jar打包成镜像、上传镜像、并生成镜像的压缩文件;
Dockerfile
FROM 10.254.9.21/library/oraclejdk:0.0.1
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ADD epic-tako.jar epic-tako.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/epic-tako.jar"]
配置文件
pack.conf
version=0.1.34.report.RL
serviceName=epic-tako
targetTagName=10.254.9.21/library/$serviceName:$version
imagePath=/opt/install/images
脚本
- 根据Dockerfile文件build出镜像
- push镜像到仓库;
- 将镜像save为
tar.gz
文件
#!/bin/sh
source ./pack.conf
echo "begin to build image"
echo "[exec]: docker build -t $targetTagName -f Dockerfile ."
docker build -t $targetTagName -f Dockerfile .
echo "[exec]: docker push $targetTagName"
docker push $targetTagName
mkdir $imagePath
echo "[exec]: docker save $targetTagName | gzip > $imagePath/$serviceName.$version.tar.gz"
docker save $targetTagName | gzip > $imagePath/$serviceName.$version.tar.gz
ls -lh $imagePath | grep $serviceName.$version.tar.gz