0. 手动打包,jar包生产后
jenkins打包。
1. Dockerfile 文件:
FROM openjdk:8
MAINTAINER "维护者 "
RUN echo "Asia/Shanghai" > /etc/timezone
LABEL 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/xxx
APP_NAME=xxx
APP_PORT=8099
VERSION=1.0.0-SNAPSHOT
cd $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" == "" ]; then
echo "应用:$APP_NAME 容器不存在。"
else
echo "应用:$APP_NAME 存在容器:$PID"
docker stop $PID
docker rm $PID
echo "容器:$PID 停止成功。"
docker rmi $PID
echo "镜像:$PID 停止成功。"
fi
echo "应用:$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 =========================="