Skip to content

Issue with ApacheDockerHttpClient Handling unix:// Connections #2380

Closed as duplicate

Description

@latamsystems

Hi Docker-Java-Devs,

I hope you're doing well.

I wanted to bring to your attention an issue I've encountered with the ApacheDockerHttpClient when connecting to Docker via a Unix socket (unix://). Specifically, when the client detects a unix:// connection, it automatically changes the host to localhost:2375. This behavior causes issues when the Docker host is intended to be a Unix socket, and not TCP.

This seems to be problematic both on Linux and Windows environments, as it tries to connect to the wrong endpoint (localhost), resulting in the following error:

HttpHostConnectException: Connect to unix://localhost:2375 failed: Connection refused

Interestingly, this issue does not occur when using the OkHttpDockerHttpClient. The OkHttp client correctly handles the unix:// scheme without trying to alter the connection to localhost, which resolves the issue.

It would be great if we could review and potentially update the handling of unix:// connections in ApacheDockerHttpClient to prevent this automatic conversion to localhost.

Let me know if you need any further details or assistance on this.

Best regards,
Luis Miguel Vasquez
Java Developer

Activity

  1. Severon96 commented on Feb 18, 2025

    @Severon96

    Yes, I can second this. Encountering the same issue.

    In addition: I just tried to bypass this bug by switching to Zerodep. Sadly this issue occurs there as well. So i'd suspect the base DockerHttpClient to have this issue.

  2. muhammetbolat commented on Feb 25, 2025

    @muhammetbolat

    I am third one to encountering this issue. Do you have any updates about solving this issue? @latamsystems @Severon96

  3. Severon96 commented on Feb 25, 2025

    @Severon96

    @muhammetbolat I ended up not using this Library.
    Instead I used a Plugin which generates a WebClient from dockers OpeAPI spec. It's Not as clean as using docker-Java but it works.

  4. latamsystems commented on Feb 25, 2025

    @latamsystems
    Author

    For everyone, the best alternative is OkDockerHttpClient

  5. Severon96 commented on Feb 25, 2025

    @Severon96

    @latamsystems no it actually isn't, since it's maintenance, stability and security isn't fully ensured on a long term basis.
    If you look into the readme for the transports you'll see what I'm talking about. It's not a appropriate basis to build your application on if you're planning it to be in production use later on.

  6. muhammetbolat commented on Feb 26, 2025

    @muhammetbolat

    Using OkDockerHttpClient solved my problem. Thank you @Severon96 @latamsystems

    However, they could not have any long term support plan for OkDockerHttpClient. They put question mark on transport.md file. They must be solve or must support this client in future.

    `

    private static final String DOCKER_HOST = "unix:///var/run/docker.sock";
    
    private final DockerClient dockerClient;
    
    
    public DockerSocketExecutor() {
        var config = DefaultDockerClientConfig.createDefaultConfigBuilder()
                .withDockerHost(DOCKER_HOST)
                .withDockerTlsVerify(false)
                .build();
    
        var httpClient = new OkDockerHttpClient.Builder()
                .dockerHost(config.getDockerHost())
                .sslConfig(config.getSSLConfig())
                .build();
    
        this.dockerClient = DockerClientBuilder.getInstance(config)
                .withDockerHttpClient(httpClient)
                .build();
    }
    

    `

  7. StefanPenndorf commented on Feb 27, 2025

    @StefanPenndorf

    Hi all,

    I experience the issue as well. I could track that issue down to an incompatability in Apache HttpClient between versions 5.2.1 and 5.4.1 . Tracking the issue further brought me to https://issues.apache.org/jira/browse/HTTPCLIENT-2348 where the developer of Apache HttpClient states about docker-java

    The maintainer of the library should upgrade to HttpClient 5.4.1 and remove references to deprecated code. We, as a project, do not support unix protocol scheme, so apparently they must have some custom code that extends HttpClient's functionality.

    This issue also brought me to #2364 which seems to upgrade docker-java to Apache HttpClient 5.4.2 and fix incompatibiltites. Release and review might be delayed at least until end of March according to @eddumelendez .

    Here are some workarounds for the meantime:

    1. Use OkDockerHttpClient as recommended by the previous commentators (didn't test myself)
    2. Downgrade to Apache HttpClient 5.2.1 (works also with newest HttpCore 5.3.3)
    3. Use fork with the fix provided by @HubFanBoy (see Upgrade Apache HttpClient to version 5.4 #2364 (comment))
  8. StefanPenndorf commented on Feb 27, 2025

    @StefanPenndorf

    This issue duplicates #2363

  9. eddumelendez commented on Apr 1, 2025

    @eddumelendez
    Member

    Closing as duplicate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions