title: Jenkins build application docker image using Gradle script . Connection reset by peer at Socke file=/run/docker.sock
body: <p>I have Grails project, I was able to build and create docker image on my machine. Now trying to run the same steps in Jenkins pipeline. It's failing with below error message.</p>
  
  <pre><code>   pipeline {
              agent any          
              stages {               
                  stage('Check Out Code') {
                      environment {
                          DEBUG_FLAGS = '-g'
                      }
                      steps {
                          echo 'Check Out..'
                          git url: https://github.com/sfgroups/grails-as-docker-image.git
  
                      }
                  }
                  stage('Build') {
                      steps {
                          timestamps {
                              ansiColor('xterm') {
                                  echo 'Building..'
                                  sh 'chmod +x gradlew'
                                  sh './gradlew clean buildImage'
                              }
                          }
                      }
                  }
  
              }          
          }
  </code></pre>
  
  <p><strong>Exception:</strong></p>
  
  <pre><code>14:38:59 Using tag 'grails-sample/grails docker build:0.1' for image.
  14:39:01 [dockerjava-jaxrs-async-0] INFO org.apache.http.impl.execchain.RetryExec - I/O exception (java.io.IOException) caught when processing request to {}-&gt;unix://localhost:80: Connection reset by peer at Socket[addr=0.0.0.0/0.0.0.0,port=0,localport=0][fd=java.io.FileDescriptor@5d7de1fa; file=/run/docker.sock; connected=true; bound=false]
  14:39:01 [dockerjava-jaxrs-async-0] ERROR com.github.dockerjava.core.async.ResultCallbackTemplate - Error during callback
  14:39:01 org.apache.http.client.ClientProtocolException
  14:39:01    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:187)
  14:39:01    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
  14:39:01    at org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:435)
  14:39:01    at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:252)
  14:39:01    at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:701)
  14:39:01    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
  14:39:01    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
  14:39:01    at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
  14:39:01    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
  14:39:01    at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:697)
  14:39:01    at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:448)
  14:39:01    at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:349)
  14:39:01    at com.github.dockerjava.jaxrs.async.POSTCallbackNotifier.response(POSTCallbackNotifier.java:29)
  14:39:01    at com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier.call(AbstractCallbackNotifier.java:50)
  14:39:01    at com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier.call(AbstractCallbackNotifier.java:24)
  14:39:01    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
  14:39:01    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  14:39:01    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  14:39:01    at java.lang.Thread.run(Thread.java:748)
  14:39:01 Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity
  14:39:01    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:108)
  14:39:01    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
  14:39:01    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
  14:39:01    ... 18 more
  14:39:01 Caused by: java.io.IOException: Connection reset by peer at Socket[addr=0.0.0.0/0.0.0.0,port=0,localport=0][fd=java.io.FileDescriptor@5d7de1fa; file=/run/docker.sock; connected=true; bound=false]
  14:39:01    at org.newsclub.net.unix.AFUNIXSocketImpl$AFUNIXOutputStream.write(AFUNIXSocketImpl.java:260)
  14:39:01    at org.apache.http.impl.io.SessionOutputBufferImpl.streamWrite(SessionOutputBufferImpl.java:124)
  14:39:01    at org.apache.http.impl.io.SessionOutputBufferImpl.flushBuffer(SessionOutputBufferImpl.java:136)
  14:39:01    at org.apache.http.impl.io.SessionOutputBufferImpl.write(SessionOutputBufferImpl.java:167)
  14:39:01    at org.apache.http.impl.io.ChunkedOutputStream.flushCacheWithAppend(ChunkedOutputStream.java:122)
  14:39:01    at org.apache.http.impl.io.ChunkedOutputStream.write(ChunkedOutputStream.java:179)
  14:39:01    at org.glassfish.jersey.message.internal.CommittingOutputStream.write(CommittingOutputStream.java:229)
  14:39:01    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$UnCloseableOutputStream.write(WriterInterceptorExecutor.java:299)
  14:39:01    at org.glassfish.jersey.message.internal.ReaderWriter.writeTo(ReaderWriter.java:116)
  14:39:01    at org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider.writeTo(AbstractMessageReaderWriterProvider.java:79)
  14:39:01    at org.glassfish.jersey.message.internal.InputStreamProvider.writeTo(InputStreamProvider.java:105)
  14:39:01    at org.glassfish.jersey.message.internal.InputStreamProvider.writeTo(InputStreamProvider.java:60)
  14:39:01    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:265)
  14:39:01    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:250)
  14:39:01    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
  14:39:01    at com.github.dockerjava.jaxrs.filter.LoggingFilter.aroundWriteTo(LoggingFilter.java:300)
  14:39:01    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
  14:39:01    at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1130)
  14:39:01    at org.glassfish.jersey.client.ClientRequest.doWriteEntity(ClientRequest.java:517)
  14:39:01    at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:499)
  14:39:01    at org.glassfish.jersey.apache.connector.ApacheConnector$2.writeTo(ApacheConnector.java:583)
  14:39:01    at org.apache.http.impl.execchain.RequestEntityProxy.writeTo(RequestEntityProxy.java:121)
  14:39:01    at org.apache.http.impl.DefaultBHttpClientConnection.sendRequestEntity(DefaultBHttpClientConnection.java:156)
  14:39:01    at org.apache.http.impl.conn.CPoolProxy.sendRequestEntity(CPoolProxy.java:160)
  14:39:01    at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:238)
  14:39:01    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
  14:39:01    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272)
  14:39:01    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
  14:39:01    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
  14:39:01    ... 20 more
  14:39:01 Caused by: org.newsclub.net.unix.AFUNIXSocketException: Connection reset by peer
  14:39:01    at org.newsclub.net.unix.NativeUnixSocket.write(Native Method)
  14:39:01    at org.newsclub.net.unix.AFUNIXSocketImpl$AFUNIXOutputStream.write(AFUNIXSocketImpl.java:251)
  14:39:01    ... 48 more
  14:39:01 :buildImage FAILED
  14:39:01 
  14:39:01 FAILURE: Build failed with an exception.
  14:39:01 
  14:39:01 * What went wrong:
  14:39:01 Execution failed for task ':buildImage'.
  14:39:01 &gt; org.apache.http.client.ClientProtocolException
  14:39:01 
  14:39:01 * Try:
  14:39:01 Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
  14:39:01 
  14:39:01 * Get more help at https://help.gradle.org
  14:39:01 
  14:39:01 Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
  14:39:01 See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warnings
  14:39:01 
  14:39:01 BUILD FAILED in 30s
  14:39:01 12 actionable tasks: 12 executed
  </code></pre>