之前使用过jenkins+maven的方法自动构建项目并推送到tomcat的方法–>传送门
由于spring boot/cloud等的微服务的流行,人们更喜欢即开即用的方式。docker作为一个免费开源的容器,越来越多的应用也都会存在一个docker版本(比如jenkins、gitlab)。不过spring boot只需要一句命令就能启动也可以不需要创建一个docker版本。
安装 必须的系统环境:
Jdk(推荐还是用Oracle JDK,Jenkins执行编译的过程还是需要Oracle JDK的,方便起见替换掉系统的openjdk) Maven Docker Git Jenkins docker hub 配置 使用docker官方的registry保存镜像,并不知道有没有限制。 创建一个私有Repo,repository的名称将作为镜像的名称
Maven配置 使用Maven构建docker镜像的话需要使用docker-maven-plugin
在pom.xml添加插件和配置信息,根据官方的实例修改配置
<plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.4.11</version> <configuration> <!-- 目标位置 --> <serverId>docker-hub</serverId> <!-- 用户名/镜像名 --> <imageName>tusik/web</imageName> <!-- Dockerfile的位置 --> <dockerDirectory>src/main/docker</dockerDirectory> <pushImage>true</pushImage> <!-- 镜像的标签,project.version在properties标签下添加 --> <imageTags> <imageTag>${project.version}</imageTag> <imageTag>latest</imageTag> </imageTags> <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint> <!-- copy the service's jar file from target into the root directory of the image --> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin> 根据上面的配置在Maven的setting.xml下添加全局的docker hub信息
...