bmuschko/gradle-docker-plugin

javaIOException: connection reset by peer when building image

RiccardoBarbieri opened this issue · 6 comments

Expected Behavior

The image is generated

Current Behavior

The images is not generated and an exception is thrown
stacktrace

Context

The exception is raised when I used this variable in gradle.properties
dockerRepository = "repository"
in the function images.add as the prefix for the repository name:
images.add("${dockerRepository}/" + project.name.split(".").last().lowercase() + ":latest")

The problem does not arise when I remove the quotes from the definition, my suggestion would be to catch the issue and throw a more appropriate exception to ease the debug process.

Steps to Reproduce (for bugs)

Set a variable in gradle.properties like so (include the quotes):
dockerRepository = "repository"
Create a tasks that extends DockerBuildImage and use that variable in the function images.add:
images.add("${dockerRepository}/" + project.name.split(".").last().lowercase() + ":latest")

@RiccardoBarbieri Would you mind posting an example of how you got around this while still using variables? I'm hitting the same issue after upgrading Gradle 7.6 -> 8.4 using the following code with the DockerBuildImage task:

images.add("dev/${customTask.archiveBaseName}:latest".replace(".","-"))
Caused by: java.lang.RuntimeException: java.io.IOException: com.sun.jna.LastErrorException: [104] Connection reset by peer
        at com.github.dockerjava.httpclient5.ApacheDockerHttpClientImpl.execute(ApacheDockerHttpClientImpl.java:195)
        at com.github.dockerjava.httpclient5.ApacheDockerHttpClient.execute(ApacheDockerHttpClient.java:9)
        at com.github.dockerjava.core.DefaultInvocationBuilder.execute(DefaultInvocationBuilder.java:228)
        at com.github.dockerjava.core.DefaultInvocationBuilder.lambda$executeAndStream$1(DefaultInvocationBuilder.java:269)

@michael-pratt i am not sure at the moment but I think that for me the problem was cause by the fact that I didn't have permission to access docker daemon, in particular I did not add the current user to docker group

@RiccardoBarbieri Ah ok. I was curious in your comment:

The problem does not arise when I remove the quotes from the definition

In my case the ${} is giving me a toString() representation of the property instead of the actual value, which causes the plugin to send invalid characters to the Docker daemon for tag names (spaces, etc). I wish I knew what was causing the different behavior because we use ${} for properties elsewhere, but for now I just access the property value using a different API and it's working as expected.

@michael-pratt
I completely confused the issue, I had another open in browser.

The problem, I think, is that when using the quotes in a gradle property declared in gradle.properties I am not declaring a string but writing the quotes in the string and when it is called using the template it keeps the quotes, docker does not accept the string.

gradle.properties does take any type declaration. So if you used quotes in the file then the property will definitely use it as-is. Also, if you use String interpolation in a Groovy-based build script, then the type will be GString and not String. The images property requires a String-typed value.

Closing as I didn't get any more response on this.