spotify docker / dockerfile maven插件[错误]复制失败

时间:2018-09-09 19:38:05

标签: docker docker-maven-plugin dockerfile-maven-plugin

我正在尝试在我的项目上执行mvn clean package docker:build,但由于以下错误而失败

  

ERROR]无法执行目标   com.spotify:docker-maven-plugin:1.1.0:build项目(default-cli)   mma-access-management-auth-server:捕获到异常:COPY失败:统计   /var/lib/docker/tmp/docker-builder181535370/mma-access-management-app-1.0.0-SNAPSHOT.jar:   没有这样的文件或目录-> [帮助1]   org.apache.maven.lifecycle.LifecycleExecutionException:失败   执行目标com.spotify:docker-maven-plugin:1.1.0:build(default-cli)   在项目mma-access-management-auth-server上:捕获到异常       在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)       在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)       在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)       在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject中   (LifecycleModuleBuilder.java:117)       在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject中   (LifecycleModuleBuilder.java:81)       在org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build   (SingleThreadedBuilder.java:51)       在org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)       在org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)       在org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)       在org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)       在org.apache.maven.cli.MavenCli.execute(MavenCli.java:955)       在org.apache.maven.cli.MavenCli.doMain(MavenCli.java:290)       在org.apache.maven.cli.MavenCli.main(MavenCli.java:194)       在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处       在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)       在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       在java.lang.reflect.Method.invoke(Method.java:498)       在org.codehaus.plexus.classworlds.launcher.Launcher.launch上增强   (Launcher.java:289)       在org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)       在org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode   (Launcher.java:415)       在org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)上由以下原因引起:   org.apache.maven.plugin.MojoExecutionException:捕获到异常       在com.spotify.docker.AbstractDockerMojo.execute(AbstractDockerMojo.java:151)       在com.spotify.docker.BuildMojo.execute(BuildMojo.java:324)       在org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)       在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)       在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)       在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)       在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject中   (LifecycleModuleBuilder.java:117)       在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject中   (LifecycleModuleBuilder.java:81)       在org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build   (SingleThreadedBuilder.java:51)       在org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)       在org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)       在org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)       在org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)       在org.apache.maven.cli.MavenCli.execute(MavenCli.java:955)       在org.apache.maven.cli.MavenCli.doMain(MavenCli.java:290)       在org.apache.maven.cli.MavenCli.main(MavenCli.java:194)       在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处       在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)       在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       在java.lang.reflect.Method.invoke(Method.java:498)       在org.codehaus.plexus.classworlds.launcher.Launcher.launch上增强   (Launcher.java:289)       在org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)       在org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode   (Launcher.java:415)       在org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)上由以下原因引起:   com.spotify.docker.client.exceptions.DockerException:COPY失败:   统计   /var/lib/docker/tmp/docker-builder181535370/mma-access-management-app-1.0.0-SNAPSHOT.jar:   没有这样的文件或目录

这是我的pom.xml

<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>
<parent>
    <groupId>com.mma</groupId>
    <artifactId>mma-access-management-parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>mma-access-management-auth-server</artifactId>
<packaging>jar</packaging>
<dependencies>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>mma-access-management-rest-api</artifactId>
        <version>${project.version}</version>
    </dependency>
</dependencies>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>1.5.8.RELEASE</version>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>1.1.0</version>
            <configuration>
                <imageName>mma/${project.artifactId}</imageName>
                <imageTags>
                    <imageTag>${project.version}</imageTag>
                    <imageTag>latest</imageTag>
                </imageTags>
                <dockerDirectory>dockerfile</dockerDirectory>
                <resources>
                    <resource>
                        <targetPath>/</targetPath>
                        <directory>${project.build.directory}</directory>
                        <include>${project.build.finalName}.jar</include>
                    </resource>
                </resources>
            </configuration>
        </plugin>
    </plugins>
</build>

这是我的Dockerfile

FROM openjdk:8u131-jdk-alpine
ENV targetDir /usr/local/access-management-app-1.0.0-SNAPSHOT.jar
ENV srcDir .
ENV jarFile mma-access-management-app-1.0.0-SNAPSHOT.jar
RUN mkdir ${targetDir}
COPY ${srcDir}/${jarFile} ${targetDir}
WORKDIR ${targetDir}
CMD ["java", "-jar", "mma-access-management-app-1.0.0-SNAPSHOT.jar"]
EXPOSE 8080/tcp

我不知道那是错的。我还尝试使用Spotify的dockerfile插件,该插件也失败了。

2 个答案:

答案 0 :(得分:2)

maven构建${project.build.finalName}.jar的jar文件与您在Dockerfile中定义的jar文件不同。

在Dockerfile中调整指定的jar文件名以匹配maven构建的jar文件,它将起作用。

FROM openjdk:8u131-jdk-alpine
ENV targetDir /usr/local/access-management-auth-server-1.0.0-SNAPSHOT.jar
ENV srcDir .
ENV jarFile mma-access-management-auth-server-1.0.0-SNAPSHOT.jar
RUN mkdir ${targetDir}
COPY ${srcDir}/${jarFile} ${targetDir}
WORKDIR ${targetDir}
CMD ["java", "-jar", "mma-access-management-auth-server-1.0.0-SNAPSHOT.jar"]
EXPOSE 8080/tcp

答案 1 :(得分:0)

看起来与Spotify插件无关。 docker构建失败于 COPY ${srcDir}/${jarFile} ${targetDir} 我猜srcDir指向src文件夹,而jar将出现在target文件夹中。