0. 手动打包,jar包生产后
jenkins打包。
1. Dockerfile 文件:
FROM openjdk:8MAINTAINER "维护者 <email>"
RUN echo "Asia/Shanghai" > /etc/timezoneLABEL description="descr ... "
ADD xxx-1.0.0-SNAPSHOT.jar xxx.jar
EXPOSE 8099
ENTRYPOINT ["java","-XX:+UseContainerSupport","-XX:MaxRAMPercentage=75.0","-server","-XX:+UseG1GC","-XX:MaxGCPauseMillis=200","-Xmx1024m","-Xms1024m","-Xmn384m","-jar","-Dspring.profiles.active=gld","xxx.jar"]
2. startup.sh 启动脚本内容:
#!/bin/sh
echo "==================== start restart docker containers ====================="APP_DIR=/root/saas/xxxAPP_NAME=xxxAPP_PORT=8099VERSION=1.0.0-SNAPSHOTcd $APP_DIR## rm -f xxx-${VERSION}.jar
## cp /data/jenkins_home/workspace/xxx/target/xxx-${VERSION}.jar ./
## sleep 3s ## 检查进程是否存在
PID=$(docker ps -a --filter name=$APP_NAME| grep -v "grep"|awk '{print $2}'|awk 'NR==2')
if [ "$PID" == "" ]; thenecho "应用:$APP_NAME 容器不存在。"
elseecho "应用:$APP_NAME 存在容器:$PID"docker stop $PIDdocker rm $PIDecho "容器:$PID 停止成功。"docker rmi $PIDecho "镜像:$PID 停止成功。"
fiecho "应用:$APP_NAME 正在启动..."docker build -t $APP_NAME .
docker run -m 2g --name $APP_NAME -d -p $APP_PORT:$APP_PORT -v /etc/localtime:/etc/localtime -v /data/logs/saas/xxx/logs:/root/saas/xxx/logs --network host $APP_NAME
echo "应用启动命令已执行,稍候请检查服务是否可用。"echo "==================== end restart docker containers =========================="