maven+docker構建springboot時,報"POST unix://localhost:80/build?t="的錯
具體報錯如下:
[INFO] Copying /root/springcloudconfig2/EurekaClient/target/EurekaClient-0.0.1-SNAPSHOT.jar -> /root/springcloudconfig2/EurekaClient/target/docker/EurekaClient-0.0.1-SNAPSHOT.jar
[INFO] Copying /root/springcloudconfig2/EurekaClient/src/main/docker/Dockerfile -> /root/springcloudconfig2/EurekaClient/target/docker/Dockerfile
[INFO] Building image luoch/EurekaClient
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 37.088s
[INFO] Finished at: Tue Dec 12 16:10:01 CST 2017
[INFO] Final Memory: 41M/98M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.3:build (default-cli) on project EurekaClient: Exception caught: Request error: POST unix://localhost:80/build?t=luoch/EurekaClient: 500: HTTP 500 Internal Server Error -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
產生錯誤的pom.xml:
<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>0.4.3</version>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}
<dockerDirectory>/src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
錯誤的原因
1.<imageName>${docker.image.prefix}/${project.artifactId}
</imageName>
imagename中字母必須全部小寫,我的${project.artifactId}中含有大寫字母
2. <dockerDirectory>/src/main/docker</dockerDirectory>
路徑改為${project.basedir}/src/main/docker
更改之後的pom.xml
<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>0.4.3</version>
<configuration>
<imageName>luo/ec</imageName>
<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
最後構建成功
[INFO] Copying /root/springcloudconfig2/EurekaClient/target/EurekaClient-0.0.1-SNAPSHOT.jar -> /root/springcloudconfig2/EurekaClient/target/docker/EurekaClient-0.0.1-SNAPSHOT.jar
[INFO] Copying /root/springcloudconfig2/EurekaClient/src/main/docker/Dockerfile -> /root/springcloudconfig2/EurekaClient/target/docker/Dockerfile
[INFO] Building image luo/ec
Step 1 : FROM frolvlad/alpine-oraclejdk8:slim
---> 335b88ca5a30
Step 2 : VOLUME /tmp
---> Using cache
---> f5f2e9ee3094
Step 3 : ADD ./EurekaClient-0.0.1-SNAPSHOT.jar app.jar
---> ac784888e583
Removing intermediate container cf5c272cdd5d
Step 4 : ENTRYPOINT java -Djava.security.egd=file:/dev/./urandom -jar /app.jar
---> Running in 7f2a62dd677a
---> e48637570e04
Removing intermediate container 7f2a62dd677a
Step 5 : EXPOSE 8761
---> Running in 046259d3e60d
---> e15cd3106f5f
Removing intermediate container 046259d3e60d
Successfully built e15cd3106f5f
[INFO] Built luo/ec
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 37.303s
[INFO] Finished at: Tue Dec 12 16:11:33 CST 2017
[INFO] Final Memory: 40M/96M
[INFO] ------------------------------------------------------------------------
注意:
1.在專案的/src/main下建立一個docker目錄,在docker目錄下建立Dockerfile檔案
2 Dockerfile
FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD ./EurekaClient-0.0.1-SNAPSHOT.jar app.jar
#RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
EXPOSE 8761
ADD 指令後面的第一個路徑是jar相對於/target/docker/Dockerfile的路徑 第二個是容器中的路徑