直接用maven打包成docker镜像的时候,就报这个错,
最开始以为是 <artifactId>spring-boot-starter-parent</artifactId><version>2.0.3.RELEASE</version> 版本问题,改成1.5.6版本就可能 顺利打包,最后排查到是打包文件名不一致,坑啊
其实就是pom.xml文件与dockerFile生成镜像文件名不一致,
pom.xml里会自带后缀名 ,就是版本号,黑色字体要注意,
<groupId>com.example.euraka</groupId>
<artifactId>demoServerClient</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
dcokerfile 文件里 ADD testeuraka-0.0.1.jar /app/app.jar 是这样
这两个地方统一就OK 所以我把pom.xml里的SNAPSHOT后缀去掉了
ADD testeuraka-0.0.1-SNAPSHOT.jar app.jar 要和pom的<artifactId>testeuraka</artifactId>
BUILD FAILURE
[INFO] ------------------------------------------------------------------------第一次打包镜像下载的东西很多, 也是报错
Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.3.RELEASE:repackage (default) on project euraka-server:
Execution default of goal org.springframework.boot:spring-boot-maven-plugin:2.0.3.RELEASE:repackage failed:
Plugin org.springframework.boot:spring-boot-maven-plugin:2.0.3.RELEASE or one of its dependencies could not be resolved:
Could not transfer artifact com.google.guava:guava:jar:11.0.2 from/to alimaven (http://maven.aliyun.com/nexus/content/groups/public/):
GET request of: com/google/guava/guava/11.0.2/guava-11.0.2.jar from alimaven
failed: Premature end of Content-Length delimited message body (expected: 1648200; received: 277655 -> [Help 1]
这是第三次才出现的错误,统统把他们放在一起处理
BUILD FAILURE
[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default-cli) on project testeuraka:
Exception caught: ADD failed: stat /var/lib/docker/tmp/docker-builder974844977/testeuraka-1.0.0.jar: no such file or directory -> [Help 1]
以下是我的正确配置
Dockerfile
FROM java:8
VOLUME /tmp
RUN mkdir /app
ADD testeuraka-0.0.1.jar /app/app.jar
ADD runboot.sh /app/
RUN bash -c 'touch /app/app.jar'
WORKDIR /app
RUN chmod a+x runboot.sh
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo 'Asia/Shanghai' >/etc/timezone
EXPOSE 5010
CMD /app/runboot.sh
下面是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>com.example.euraka</groupId>
<artifactId>testeuraka</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>testeuraka</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.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>
<version.jackson>2.9.2</version.jackson>
<java.version>1.8</java.version>
<docker.url>http://192.168.11.233:2375</docker.url>
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<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>
<configuration>
<dockerHost>${docker.url}</dockerHost>
<imageName>${project.name}:${project.version}</imageName>
<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
<skipDockerBuild>false</skipDockerBuild>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</project>