maven project
Spring Boot microservices
包含多个模块(目前只有一个)
在root folder
pom.xml
包含
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>be.demo.microservices</groupId>
<artifactId>master</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>hello-service</module>
</modules>
</project>
在hello-service folder
中,pom.xml
包含
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>be.demo.microservices</groupId>
<artifactId>hello-service</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<docker.image.prefix>springio</docker.image.prefix>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<imageTags>
<imageTag>${project.version}</imageTag>
<imageTag>latest</imageTag>
</imageTags>
<baseImage>openjdk:8-jdk-alpine</baseImage>
<entryPoint>["sh","-c","java -Djava.security.egd=file:/dev/./urandom -jar /${project.build.finalName}.jar"]</entryPoint>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</project>
使用mvn clean package docker:build
构建项目时,我有
...
[INFO] --- spring-boot-maven-plugin:2.0.1.RELEASE:repackage (default) @ hello-service ---
[INFO]
[INFO] --- docker-maven-plugin:1.0.0:build (default-cli) @ hello-service ---
[INFO] Using authentication suppliers: [ConfigFileRegistryAuthSupplier]
[INFO] Copying D:\dev\microservices\demo\hello-service\target\hello-service-1.0.0-SNAPSHOT.jar -> D:\dev\microservices\demo\hello-service\target\docker\hello-service-1.0.0-SNAPSHOT.jar
[INFO] Building image springio/hello-service
Step 1/3 : FROM openjdk:8-jdk-alpine
---> 224765a6bdbe
Step 2/3 : ADD /hello-service-0.0.1-SNAPSHOT.jar //
---> 259b1622e107
Step 3/3 : ENTRYPOINT ["sh","-c","java -Djava.security.egd=file:/dev/./urandom -jar /hello-service-1.0.0-SNAPSHOT.jar"]
---> Running in e86870c47b6a
Removing intermediate container e86870c47b6a
---> 847840116367
ProgressMessage{id=null, status=null, stream=null, error=null, progress=null, progressDetail=null}
Successfully built 847840116367
Successfully tagged springio/hello-service:latest
[INFO] Built springio/hello-service
[INFO] Tagging springio/hello-service with 1.0.0-SNAPSHOT
[INFO] Tagging springio/hello-service with latest
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building master 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ master ---
[INFO]
[INFO] --- docker-maven-plugin:1.0.0:build (default-cli) @ master ---
[INFO] Using authentication suppliers: [ConfigFileRegistryAuthSupplier]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] hello-service ...................................... SUCCESS [ 9.881 s]
[INFO] master ............................................. FAILURE [ 0.102 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.650 s
[INFO] Finished at: 2018-04-18T13:33:49+02:00
[INFO] Final Memory: 54M/520M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default-cli) on project master: Exception caught: Must specify baseImage if dockerDirectory is null -> [Help 1]
[ERROR] .....
所以服务是打包的,图像是构建的但是我不明白为什么在主pom maven中试图建立一个图像,即使它里面没有docker插件?
答案 0 :(得分:0)
默认情况下,这个docker-maven-plugin与maven的包构建阶段绑定。
检查以下链接bind-docker-commands-to-maven-phases
您可以跳过绑定到Maven阶段的Docker目标:
-DskipDockerBuild to skip image build
-DskipDockerTag to skip image tag
-DskipDockerPush to skip image push
-DskipDocker to skip any Docker goals