Reputation: 41580
Spring's WebClient underlyingly uses Netty which access to Unix domain sockets. I am trying to make it access /var/run/docker.sock
so that I can perform operations using the API as I need /services
which is not supported by the docker-java library.
My current workaround is to create a socat container that exposes the Docker socket to TCP within an internal network which in turn allows me to use WebClient's HTTP connections.
Though come to think of it, having this workaround gives one benefit of not needing to put a larger Java application on the manager node.
However, I am still curious how to connect to the unix domain docket.
Upvotes: 3
Views: 1640
Reputation: 8992
You can create a Netty HttpClient following their documentation regarding Unix Domain Sockets here.
import io.netty.channel.unix.DomainSocketAddress;
import reactor.netty.http.client.HttpClient;
HttpClient client = HttpClient.create()
.remoteAddress(() -> new DomainSocketAddress("/var/run/docker.sock"));
Then you can tell WebClient to use this HttpClient like this.
WebClient.builder()
.clientConnector(new ReactorClientHttpConnector(client))
.build();
Upvotes: 3