-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#291 Docker for Windows support over TCP
- Loading branch information
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
.../src/main/java/org/testcontainers/dockerclient/NamedPipeSocketClientProviderStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.testcontainers.dockerclient; | ||
|
||
import com.github.dockerjava.core.DefaultDockerClientConfig; | ||
import com.github.dockerjava.core.DockerClientConfig; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.File; | ||
|
||
public class NamedPipeSocketClientProviderStrategy extends DockerClientProviderStrategy { | ||
|
||
private static final int PING_TIMEOUT_DEFAULT = 5; | ||
private static final String PING_TIMEOUT_PROPERTY_NAME = "testcontainers.namedpipesocketprovider.timeout"; | ||
|
||
@Override | ||
public void test() throws InvalidConfigurationException { | ||
if (!new File("\\\\.\\pipe\\docker_engine").exists()) { | ||
throw new InvalidConfigurationException("this strategy only works with Docker for Windows"); | ||
} | ||
|
||
config = tryConfiguration("tcp://localhost:2375"); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Docker for Windows (via TCP port 2375)"; | ||
} | ||
|
||
@NotNull | ||
protected DockerClientConfig tryConfiguration(String dockerHost) { | ||
config = DefaultDockerClientConfig.createDefaultConfigBuilder() | ||
.withDockerHost(dockerHost) | ||
.withDockerTlsVerify(false) | ||
.build(); | ||
client = getClientForConfig(config); | ||
|
||
final int timeout = Integer.getInteger(PING_TIMEOUT_PROPERTY_NAME, PING_TIMEOUT_DEFAULT); | ||
ping(client, timeout); | ||
|
||
return config; | ||
} | ||
} |