Skip to content

Issue with ApacheDockerHttpClient Handling unix:// Connections #2380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
latamsystems opened this issue Feb 15, 2025 · 9 comments
Closed

Issue with ApacheDockerHttpClient Handling unix:// Connections #2380

latamsystems opened this issue Feb 15, 2025 · 9 comments

Comments

@latamsystems
Copy link

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

@Severon96
Copy link

Severon96 commented Feb 18, 2025

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.

@muhammetbolat
Copy link

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

@Severon96
Copy link

@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.

@latamsystems
Copy link
Author

For everyone, the best alternative is OkDockerHttpClient

@Severon96
Copy link

@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.

@muhammetbolat
Copy link

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();
}

`

@StefanPenndorf
Copy link

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))

@StefanPenndorf
Copy link

This issue duplicates #2363

@eddumelendez
Copy link
Member

Closing as duplicate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants