This issue relates to the following bmuschko/gradle-docker-plugin#432
The Docker Gradle plugin is using the docker-java library in version 3.0.12. When using the plugin in a Gradle build under Windows the following exception occurs (only snippet):
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:95)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:76)
... 70 more
Caused by: java.io.IOException: Der Prozess kann nicht auf die Datei zugreifen, da ein anderer Prozess einen Teil der Datei gesperrt hat
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:2146)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:2102)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:2123)
at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1107)
at com.github.dockerjava.core.util.CompressArchiveUtil.archiveTARFiles(CompressArchiveUtil.java:105)
at com.github.dockerjava.core.dockerfile.Dockerfile$ScannedResult.buildDockerFolderTar(Dockerfile.java:135)
... 92 more
Suppressed: java.io.IOException: This archives contains unclosed entries.
at org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.finish(TarArchiveOutputStream.java:225)
at org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.close(TarArchiveOutputStream.java:241)
at com.github.dockerjava.core.util.CompressArchiveUtil.archiveTARFiles(CompressArchiveUtil.java:109)
at com.github.dockerjava.core.dockerfile.Dockerfile$ScannedResult.buildDockerFolderTar(Dockerfile.java:135)
The IOException tells me that someone has locked a file the library wants to use and include in the context TAR file. But this bug only happens under Windows, when I run the exact same build on my Mac everything is OK.
Any ideas how to analyse / fix this? If you need a project to reproduce the behaviour, you can use https://github.com/lreimer/everything-as-code
@lreimer I don't think this is a bug. To build image you have to send build context to docker daemon. In your case one of files is locked (partially) and can't be read. How would you fix that? The only solution is to release the lock.
But why is it working OK under MacOS and only complaining under Windows? Is there maybe some kind of flag one could give to the Apache Commons TarArchiveOutputStream.finish() method?
@lreimer because only on Windows some other process locks that file. The solution with _flag_ is tricky, why we should silently remove locked files from build context? What if they are required to build an image?
If I recall correctly, I also had similar issues and it seemed like the Gradle process itself (via daemon?) holds a lock on those files. My workaround was to copy the build context to another directory.
My workaround was to copy the build context to another directory
Or just create .dockerignore excluding .gradle dir and other not needed stuff. Build will be faster!
Thanks for all your comments.
I already have a .dockerignore file. The file I want to add via COPY is a .tar file produced by the application plugin in the Gradle build/ directory.
So I will try to narrow down the build/ directory even further using .dockerignore. Maybe that helps. Otherwise I will try to copy the file somewhere else and use it from there.