0

I am attempting to automatically manage my application in a Docker container using the Spotify Docker Client for my integration tests with Docker for Mac.

DockerClient docker = new DefaultDockerClient.fromEnv().build();

HostConfig hostConfig = HostConfig.builder()
    .portBindings(new HashMap<String, List<PortBinding>>(){{
        put("8080", Arrays.asList(PortBinding.of("localhost", 8080)));
    }}).build();

ContainerConfig containerConfig = ContainerConfig.builder()
    .hostConfig(hostConfig)
    .exposedPorts("8080")
    .image("my-app")
    .portSpecs(Arrays.asList("8080:8080"))
    .build();

ContainerCreation createdContainer = docker.createContainer(containerConfig);

the createContainer call fails:

2091 [jersey-client-async-executor-0] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager  - Connection request: [route: {}->unix://localhost:80][total kept alive: 0; route allocated: 0 of 100; total allocated: 0 of 100]
2091 [jersey-client-async-executor-0] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager  - Connection leased: [id: 1][route: {}->unix://localhost:80][total kept alive: 0; route allocated: 1 of 100; total allocated: 1 of 100]
2091 [jersey-client-async-executor-0] DEBUG org.apache.http.impl.execchain.MainClientExec  - Opening connection {}->unix://localhost:80
2456 [jersey-client-async-executor-0] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator  - Connecting to localhost/127.0.0.1:80
2476 [jersey-client-async-executor-0] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection  - http-outgoing-1: Shutdown connection
2516 [jersey-client-async-executor-0] DEBUG org.apache.http.impl.execchain.MainClientExec  - Socket is not connected
java.io.IOException: Socket is not connected
    at jnr.enxio.channels.NativeSocketChannel.shutdownInput(NativeSocketChannel.java:102)
    at com.spotify.docker.client.ApacheUnixSocket.shutdownInput(ApacheUnixSocket.java:280)
    at com.spotify.docker.client.ApacheUnixSocket.close(ApacheUnixSocket.java:273)
...

Due to some weirdness, where the stacktrace mentions unix://localhost:80, under the hood it is actually using the socket url unix:///var/run/docker.sock. I have confirmed this by stepping through with the debugger.

Docker works perfectly fine otherwise; I can connect to the socket via 'curl' and I can use docker via the terminal normally.

ThisIsNoZaku
  • 2,213
  • 2
  • 26
  • 37
  • once there was a problem like this in a project of mine. there was some configurations wrong/missing/changed at the test-scoped in the test-packages/test usage. do you have any configurations which could be diffrent under test? – LenglBoy Oct 24 '17 at 07:11
  • This does not refer to the problem that you are facing. But for me it seems that you are reinventing [testcontainers](https://github.com/testcontainers/testcontainers-java). Maybe it will help you and will make your life with integration tests easier – Sergii Bishyr Oct 24 '17 at 09:18
  • @SergiiBishyr The application is locked to Java 6. – ThisIsNoZaku Oct 24 '17 at 14:05

0 Answers0