Description
Hi, occurred An SocketException when using loadImageCmd, can u help me?
when I ran loadImage method in a main method, error occurred as follow:
17:19:01.983 [main] DEBUG com.github.dockerjava.httpclient5.ApacheDockerHttpClientImpl$ApacheResponse - Failed to close the response
java.net.SocketException: socket closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at org.apache.hc.client5.http.impl.io.LoggingInputStream.read(LoggingInputStream.java:81)
at org.apache.hc.core5.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:149)
at org.apache.hc.core5.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:280)
at org.apache.hc.core5.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:261)
at org.apache.hc.core5.http.impl.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:222)
at org.apache.hc.core5.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:183)
at org.apache.hc.core5.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:210)
at org.apache.hc.core5.http.impl.io.ChunkedInputStream.close(ChunkedInputStream.java:319)
at org.apache.hc.core5.io.Closer.close(Closer.java:48)
at org.apache.hc.core5.http.impl.io.IncomingHttpEntity.close(IncomingHttpEntity.java:112)
at org.apache.hc.core5.http.io.entity.HttpEntityWrapper.close(HttpEntityWrapper.java:120)
at org.apache.hc.core5.io.Closer.close(Closer.java:48)
at org.apache.hc.core5.http.message.BasicClassicHttpResponse.close(BasicClassicHttpResponse.java:93)
at org.apache.hc.client5.http.impl.classic.CloseableHttpResponse.close(CloseableHttpResponse.java:200)
at com.github.dockerjava.httpclient5.ApacheDockerHttpClientImpl$ApacheResponse.close(ApacheDockerHttpClientImpl.java:256)
at com.github.dockerjava.core.DefaultInvocationBuilder.postStream(DefaultInvocationBuilder.java:193)
at com.github.dockerjava.core.exec.LoadImageCmdExec.execute(LoadImageCmdExec.java:24)
at com.github.dockerjava.core.exec.LoadImageCmdExec.execute(LoadImageCmdExec.java:10)
at com.github.dockerjava.core.exec.AbstrSyncDockerCmdExec.exec(AbstrSyncDockerCmdExec.java:21)
at com.github.dockerjava.core.command.AbstrDockerCmd.exec(AbstrDockerCmd.java:35)
at com.eccom.jks.api.util.DockerUtils.loadImage(DockerUtils.java:482)
at com.eccom.jks.api.util.DockerUtils.main(DockerUtils.java:495)
Disconnected from the target VM, address: '127.0.0.1:53766', transport: 'socket'
my work env:
- Windows 10
- JetBrain IDEA 2018
- Docker desktop(open 2375 remote port)
- Harbor V2.8.0(on a remote linux server)
- jdk vresion: jdk8
- Java dependency: docker-java 3.3.0 docker-java-transport-httpclient5 3.3.0
public DockerClient getDockerClient() {
DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost("tcp://" + "127.0.0.1:2375")
.build();
DockerHttpClient httpClient = new ApacheDockerHttpClient.Builder()
.dockerHost(config.getDockerHost())
.maxConnections(100)
.connectionTimeout(Duration.ofSeconds(30))
.responseTimeout(Duration.ofSeconds(45))
.build();
return DockerClientImpl.getInstance(config, httpClient);
}
public void loadImage(String filePath){
DockerClient dockerClient = getDockerClient();
try (InputStream inputStream = new FileInputStream(filePath)) {
dockerClient.loadImageCmd(inputStream).exec();
} catch (Exception e) {
e.printStackTrace();
}
}