Hi all,
seems dockerfile-maven can't hanle COPY statement correctly, when the COPY src is a directory, it will encounter error that:
Could not copy files: /home/jenkins/workspace/deploy_owl_dashboard_local/UI/target/docker/html (Is a directory
Dockerfile
FROM docker.io/nginx:latest
MAINTAINER [email protected]
COPY default.conf /etc/nginx/conf.d/default.conf.templ
COPY conf-builder.sh /usr/bin/conf-builder.sh
COPY html /usr/share/nginx/html
RUN chmod +x /usr/bin/conf-builder.sh
EXPOSE 80 443
CMD conf-builder.sh &&\
nginx -g "daemon off;"
maven errors:
[INFO] Building Docker context /home/jenkins/workspace/deploy_owl_dashboard_local/UI/target/docker
[INFO]
[INFO] Image will be built as xxxxx
[INFO]
[INFO] Step 1 : FROM docker.io/nginx:latest
[INFO] Pulling from library/nginx
[INFO] Digest: sha256:b644a3bdb2888d53c0d0c24aafe06ad8c88936ca5e127088a7a5686a54ea0713
[INFO] Status: Image is up to date for nginx:latest
[INFO] ---> 66216d141be6
[INFO] Step 2 : MAINTAINER xxx
[INFO] ---> Using cache
[INFO] ---> 1e318e2f3309
[INFO] Step 3 : COPY default.conf /etc/nginx/conf.d/default.conf.templ
[INFO] ---> Using cache
[INFO] ---> 92076a0110ab
[INFO] Step 4 : COPY conf-builder.sh /usr/bin/conf-builder.sh
[INFO] ---> Using cache
[INFO] ---> e0590a8bba04
[INFO] Step 5 : COPY html /usr/share/nginx/html
[INFO] ---> Using cache
[INFO] ---> 36361d53a7de
[INFO] Step 6 : RUN chmod +x /usr/bin/conf-builder.sh
[INFO] ---> Using cache
[INFO] ---> 4a68a1c99a9e
[INFO] Step 7 : EXPOSE 80 443
[INFO] ---> Using cache
[INFO] ---> 62154791d60e
[INFO] Step 8 : CMD conf-builder.sh && nginx -g "daemon off;"
[INFO] ---> Using cache
[INFO] ---> 144d90b3062e
[INFO] Successfully built 144d90b3062e
[INFO]
[INFO] Detected build of image with id 144d90b3062e
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 49.740 s
[INFO] Finished at: 2017-09-12T03:04:00+00:00
[INFO] Final Memory: 45M/946M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:dockerfile-maven-plugin:1.3.5:build (package) on project UI: Could not copy files: /home/jenkins/workspace/deploy_owl_dashboard_local/UI/target/docker/html (Is a directory) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.spotify:dockerfile-maven-plugin:1.3.5:build (package) on project UI: Could not copy files
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
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:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
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: Could not copy files
at com.spotify.plugin.dockerfile.AbstractDockerMojo.writeTestMetadata(AbstractDockerMojo.java:286)
at com.spotify.plugin.dockerfile.AbstractDockerMojo.writeMetadata(AbstractDockerMojo.java:246)
at com.spotify.plugin.dockerfile.BuildMojo.execute(BuildMojo.java:121)
at com.spotify.plugin.dockerfile.AbstractDockerMojo.tryExecute(AbstractDockerMojo.java:227)
at com.spotify.plugin.dockerfile.AbstractDockerMojo.execute(AbstractDockerMojo.java:216)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 20 more
Caused by: java.io.FileNotFoundException: /home/jenkins/workspace/deploy_owl_dashboard_local/UI/target/docker/html (Is a directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at com.google.common.io.Files$FileByteSource.openStream(Files.java:126)
at com.google.common.io.Files$FileByteSource.openStream(Files.java:116)
at com.google.common.io.ByteSource.copyTo(ByteSource.java:267)
at com.google.common.io.Files.copy(Files.java:315)
at com.spotify.plugin.dockerfile.AbstractDockerMojo.writeTestMetadata(AbstractDockerMojo.java:284)
... 26 more
[ERROR]
[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
I can't seem to COPY or ADD. When I build it hangs forever at
Image will be built as Foo:latest
Mine is not when the src is a directory though. It appears like this.
COPY target/app.war /usr/local/tomcat/webapps
What's really interesting is when I remove the app.war from target the directory the build produces output about the FROM lines (pulling down the image, finding the cache, etc) AND the COPY statement failing because the file doesn't exist. Is this from the docker client or from this plugin?
I am getting same error on linux machine, I tried multiple versions of plugin from 1.3.3 to 1.3.6
[ERROR] COPY failed: stat /home/var-lib-docker/tmp/docker-builder542183900/target/server-2.0.101-SNAPSHOT-dist.tar.gz: no such file or directory
To be specific this happens when context path is setup.
I'm seeing the same issue - also tracing back to the writeTestMetadata method...
Caused by: org.apache.maven.plugin.MojoExecutionException: Could not copy files
at com.spotify.plugin.dockerfile.AbstractDockerMojo.writeTestMetadata(AbstractDockerMojo.java:299)
at com.spotify.plugin.dockerfile.AbstractDockerMojo.writeMetadata(AbstractDockerMojo.java:259)
at com.spotify.plugin.dockerfile.BuildMojo.execute(BuildMojo.java:121)
at com.spotify.plugin.dockerfile.AbstractDockerMojo.tryExecute(AbstractDockerMojo.java:240)
at com.spotify.plugin.dockerfile.AbstractDockerMojo.execute(AbstractDockerMojo.java:229)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 20 more
Caused by: java.io.FileNotFoundException: <<sanitized>>/target/docker/BOOT-INF (Is a directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at com.google.common.io.Files$FileByteSource.openStream(Files.java:126)
at com.google.common.io.Files$FileByteSource.openStream(Files.java:116)
at com.google.common.io.ByteSource.copyTo(ByteSource.java:267)
at com.google.common.io.Files.copy(Files.java:315)
at com.spotify.plugin.dockerfile.AbstractDockerMojo.writeTestMetadata(AbstractDockerMojo.java:297)
... 26 more
Has anyone found a workaround for this?
I think I figured it out... or at least a workaround.
I was previously copying files into /target/docker and then had my dockerfile pulling files etc from there.
I switched to using /target/dockerbuild as my scratch directory, because /target/docker looks like the plugin itself is trying to put stuff there...
that switch made it build ok
I think the root of the problem is using a docker context directory of target/docker, which the plugin aims to use itself to keep some state in.
The best fix is probably to have the plugin throw an error if this is the path used as context directory.
For anyone running into this issue today that _really_ wants to use a context directory of target/directory, note that it is possible to disable the writeTestMetadata behavior by setting either -Ddockerfile.writeTestMetadata=false or adding <writeTestMetadata>false</writeTestMetadata> to the plugin's <configuration>.
In this case, I don't have the Dockerfile in the target/docker, I have that dockerfile at the top level... but it's referencing files that happen to live in target/docker in the COPY or ADD directives - could the plugin detect that too?
moving the default dockerInfoDirectory target directory from to target/docker to something more plugin-specific like target/dockerfile-maven-plugin-buildinfo seems like it would also make any collisions with the stuff the plugin writes much less likely
Do you mean that other parts of your maven build are putting files/directories under target/docker for the Dockerfile to later reference when the container is built?
Its better to store the files (you want to copy to your image ) in a separate folder in target except "target/docker" . It works for me at least.
I manually deleted target/docker and after that everything was fine. Could help in your case. Probably a mvn clean would do the trick as well.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
In case anyone else runs into it. I had stupidly configured maven-resources-plugin to move some files around to create a docker build context in a subdirectory of /target/docker
The current state of dockerfile-maven-plugin does not allow for this. I suspect it expects the target/docker directory to be empty whenever the build completes, so it can write its bookkeeping info (... the image-id, image-name, repository, and tag files).
Im facing the same issue.
Ive solved it by just updating the JAR_FILE arg in Maven:
<pluginManagement>
<plugins>
<!-- Preferences for creating a docker image from a Dockerfile-->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker.plugin.version}</version>
<executions>
....
</executions>
<configuration>
.....
<buildArgs>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</pluginManagement>
please help i want to copy the .war file to the docker instance using publish over ssh
Step 3/3 : COPY target/maven.war /usr/local/tomcat/webapps
COPY failed: stat /var/lib/docker/tmp/docker-builder270180134/target/maven.war: no such file or directory
SSH: EXEC: completed after 403 ms
SSH: Disconnecting configuration [Docker] ...
ERROR: Exception when publishing, exception message [Exec exit status not zero. Status [1]]
Build step 'Send files or execute commands over SSH' changed build result to UNSTABLE
SSH: Connecting from host [ip-172-31-71-128.ec2.internal]
SSH: Connecting with configuration [Docker] ...
SSH: EXEC: STDOUT/STDERR from command [docker run -d --name devops -p 8090:8080 devops] ...
Unable to find image 'devops:latest' locally
docker: Error response from daemon: pull access denied for devops, repository does not exist or may require 'docker login'.
See 'docker run --help'.
SSH: EXEC: completed after 201 ms
SSH: Disconnecting configuration [Docker] ...
ERROR: Exception when publishing, exception message [Exec exit status not zero. Status [125]]
Finished: UNSTABLE
Most helpful comment
I think I figured it out... or at least a workaround.
I was previously copying files into
/target/dockerand then had my dockerfile pulling files etc from there.I switched to using
/target/dockerbuildas my scratch directory, because/target/dockerlooks like the plugin itself is trying to put stuff there...that switch made it build ok