Blogger Information
Blog 291
fans 0
comment 0
visits 350698
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Springboot docker jenkins 自动化部署并上传镜像
Original
618 people have browsed it

阿里云开源镜像站:
https://developer.aliyun.com/mirror/?utm_content=g_1000303593

springboot + docker + jenkins自动化部署项目,jenkins、mysql、redis都是docker运行的,并且没有使用虚拟机,就在阿里云服务器(centos7)运行

1、前期准备工作不说了

2、在项目根目录下新建Dockerfile
file

Dockerfile文件内容为:

  1. #基础镜像
  2. FROM openjdk:12
  3. #作者
  4. MAINTAINER demo <demo@qq.com>
  5. VOLUME /tmp
  6. #指定配置文件,以及jar包在服务器上的路径
  7. ENTRYPOINT ["java","-Dspring.profiles.active=prod","-jar","/lcy/work/tools/tools.jar"]
  8. #暴露端口
  9. EXPOSE 8092

3、在服务器找个目录新建一个.sh文件

  1. #!/bin/sh
  2. echo '================开始构建镜像=============='
  3. #镜像名称
  4. IMAGE_NAME='registry.cn-beijing.aliyuncs.com/???/tools'
  5. #打包后在jenkins的地址
  6. SOURCE_PATH='/lcy/jenkins/workspace/tools'
  7. #Dockerfile执行jar包的地址
  8. BASE_PATH='/lcy/work/tools'
  9. echo IMAGE_NAME=$IMAGE_NAME
  10. echo '================复制JAR包==================='
  11. echo $SOURCE_PATH/target/tools-0.0.1-SNAPSHOT.jar
  12. cp $SOURCE_PATH/target/tools-0.0.1-SNAPSHOT.jar $BASE_PATH/tools.jar
  13. chmod -R 777 $BASE_PATH/tools.jar
  14. echo '================复制完成===================='
  15. echo '================当前docker版本=============='
  16. docker -v
  17. echo '================构建镜像开始================'
  18. docker build -t $IMAGE_NAME -f $SOURCE_PATH/Dockerfile .
  19. echo '================构建镜像结束================'
  20. #输入要推送镜像的地址,根据镜像仓库提示的地址复制
  21. echo '================推送镜像开始================'
  22. docker login --username=??? --password=??? registry-vpc.cn-beijing.aliyuncs.com
  23. docker push $IMAGE_NAME
  24. echo '================推送镜像结束================'
  25. echo '================获取容器id=================='
  26. CID=$(docker ps | grep "$IMAGE_NAME" | awk '{print $1}')
  27. echo 容器id=$CID
  28. echo '================获取镜像id=================='
  29. IID=$(docker images | grep "$IMAGE_NAME" | awk '{print $3}')
  30. echo 镜像id=$IID
  31. if [ -n "$CID" ]; then
  32. echo 存在$IMAGE_NAME容器,停止容器并删除
  33. docker stop tools
  34. docker rm tools
  35. else
  36. echo 不存在$IMAGE_NAME容器,开始启动
  37. docker run -p 8092:8092 -d --name tools -v $BASE_PATH:$BASE_PATH $IMAGE_NAME
  38. fi

4、配置jenkins,执行新建的.sh文件(记得给好权限)其它的配置就不说了,比如github的配置
file
5、运行结果
file

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post