我想在 Jenkins 中使用 Dockerfile 为 Maven 项目创建一个映像。这是一个 Spring Boot 项目。我已经将 Jenkins 作为 docker 容器运行。我使用的是 Windows 10。
我的 dockerfile 是:
FROM maven:3.5-jdk-8-alpine
WORKDIR /app
COPY pom.xml /app/
COPY Dockerfile /app/
RUN ["mvn", "package"]
FROM tomcat:9
EXPOSE 8087
COPY /app/target/*.war /usr/local/tomcat/webapps/
CMD ["catalina.sh","run"]
Run Code Online (Sandbox Code Playgroud)
pom.xml 的插件部分是:
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.example.restcurd.RestcurdApplication</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.10</version>
<executions>
<execution>
<id>build</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<repository>pomkiticat/${project.name}</repository>
<tag>${project.version}</tag>
<skipDockerInfo>true</skipDockerInfo>
<pullNewerImage>false</pullNewerImage>
</configuration>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)
我还选择了 docker Desktop 中的选项Expose daemon on …