spotify docker/dockerfile maven plugin [ERROR] Copy failed

3.1k Views Asked by At

I am trying to execute the mvn clean package docker:build on my project it fails with the following error

ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.1.0:build (default-cli) on project mma-access-management-auth-server: Exception caught: COPY failed: stat /var/lib/docker/tmp/docker-builder181535370/mma-access-management-app-1.0.0-SNAPSHOT.jar: no such file or directory -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.spotify:docker-maven-plugin:1.1.0:build (default-cli) on project mma-access-management-auth-server: Exception caught at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:51) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:309) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290) at org.apache.maven.cli.MavenCli.main (MavenCli.java:194) at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356) Caused by: org.apache.maven.plugin.MojoExecutionException: Exception caught at com.spotify.docker.AbstractDockerMojo.execute (AbstractDockerMojo.java:151) at com.spotify.docker.BuildMojo.execute (BuildMojo.java:324) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:134) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:51) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:309) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290) at org.apache.maven.cli.MavenCli.main (MavenCli.java:194) at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356) Caused by: com.spotify.docker.client.exceptions.DockerException: COPY failed: stat /var/lib/docker/tmp/docker-builder181535370/mma-access-management-app-1.0.0-SNAPSHOT.jar: no such file or directory

This is my 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>

This is my 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

I don't know that is going wrong. I also tried to use the dockerfile plugin from spotify which also failed.

2

There are 2 best solutions below

0
On BEST ANSWER

The jar file of the maven build ${project.build.finalName}.jar differs from the one you have defined in the Dockerfile.

Adjust the specified jar filename in the Dockerfile to match the jar of the maven build and it will work.

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
0
On

Does not look like a issue with the spotify plugin. The docker build is failing at COPY ${srcDir}/${jarFile} ${targetDir} I guess the srcDir points to the src folder whereas the jar will be present in the target folder.