Skip to content

Commit e925e53

Browse files
committed
Add getDockerHost() to DockerProvider
1 parent 6bf1f5b commit e925e53

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

src/main/java/io/github/intisy/docker/DockerProvider.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,24 @@ public static DockerProvider get() {
137137
*/
138138
public abstract void ensureInstalled() throws IOException;
139139

140+
/**
141+
* Get the Docker host URL for connecting to this provider's Docker daemon.
142+
* This can be used as the {@code DOCKER_HOST} environment variable or passed
143+
* to other tools that need to connect to this Docker instance.
144+
* <p>
145+
* Returns values like:
146+
* <ul>
147+
* <li>{@code unix:///path/to/docker.sock} (Linux)</li>
148+
* <li>{@code npipe:////./pipe/docker_java_abc123} (Windows native)</li>
149+
* <li>{@code tcp://localhost:2375} (macOS Lima, Windows WSL2)</li>
150+
* </ul>
151+
* <p>
152+
* Must be called after {@link #start()}.
153+
*
154+
* @return The Docker host URL string
155+
*/
156+
public abstract String getDockerHost();
157+
140158
/**
141159
* Check if NVIDIA GPU is available on this system.
142160
* @return true if an NVIDIA GPU is detected, false otherwise

src/main/java/io/github/intisy/docker/LinuxDockerProvider.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ public void start() throws IOException, InterruptedException {
226226
log.info("Docker daemon started (instance: {})", instanceId);
227227
}
228228

229+
@Override
230+
public String getDockerHost() {
231+
return "unix://" + dockerSocketPath.toString();
232+
}
233+
229234
@Override
230235
public DockerClient getClient() {
231236
if (this.dockerClient == null) {

src/main/java/io/github/intisy/docker/MacDockerProvider.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,11 @@ private boolean waitForDocker() throws InterruptedException {
436436
return false;
437437
}
438438

439+
@Override
440+
public String getDockerHost() {
441+
return "tcp://localhost:" + dockerPort;
442+
}
443+
439444
@Override
440445
public DockerClient getClient() {
441446
if (this.dockerClient == null) {

src/main/java/io/github/intisy/docker/WindowsDockerProvider.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,16 @@ private boolean isWsl2Available() {
750750

751751
private String wslIpAddress;
752752

753+
@Override
754+
public String getDockerHost() {
755+
if (usingWsl2) {
756+
String host = wslIpAddress != null ? wslIpAddress : "localhost";
757+
return "tcp://" + host + ":" + dockerPort;
758+
} else {
759+
return "npipe://" + dockerPipePath.toString().replace("\\", "/");
760+
}
761+
}
762+
753763
@Override
754764
public DockerClient getClient() {
755765
if (this.dockerClient == null) {

0 commit comments

Comments
 (0)