Skip to content

Commit

Permalink
#291 Docker for Windows support over TCP
Browse files Browse the repository at this point in the history
  • Loading branch information
bsideup authored and rnorth committed Mar 3, 2017
1 parent 932a60b commit e8bf32e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public class DockerClientFactory {
asList(new EnvironmentAndSystemPropertyClientProviderStrategy(),
new UnixSocketClientProviderStrategy(),
new ProxiedUnixSocketClientProviderStrategy(),
new DockerMachineClientProviderStrategy());
new DockerMachineClientProviderStrategy(),
new NamedPipeSocketClientProviderStrategy());
private String activeApiVersion;
private String activeExecutionDriver;

Expand Down
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;
}
}

0 comments on commit e8bf32e

Please sign in to comment.