Skip to content

Commit

Permalink
Merge branch 'mbaechler-Issue-76'
Browse files Browse the repository at this point in the history
  • Loading branch information
rnorth committed Feb 24, 2016
2 parents eebda68 + 3c14cfb commit d25410d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Expand Up @@ -16,6 +16,7 @@
import org.testcontainers.dockerclient.DockerConfigurationStrategy;
import org.testcontainers.dockerclient.DockerMachineConfigurationStrategy;
import org.testcontainers.dockerclient.EnvironmentAndSystemPropertyConfigurationStrategy;
import org.testcontainers.dockerclient.UnixSocketConfigurationStrategy;

import java.util.List;

Expand All @@ -38,7 +39,8 @@ public class DockerClientFactory {

private static final List<DockerConfigurationStrategy> CONFIGURATION_STRATEGIES =
asList(new EnvironmentAndSystemPropertyConfigurationStrategy(),
new DockerMachineConfigurationStrategy());
new DockerMachineConfigurationStrategy(),
new UnixSocketConfigurationStrategy());

/**
* Private constructor
Expand Down
@@ -0,0 +1,32 @@
package org.testcontainers.dockerclient;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.core.DockerClientBuilder;
import com.github.dockerjava.core.DockerClientConfig;

public class UnixSocketConfigurationStrategy implements DockerConfigurationStrategy {

public static final String SOCKET_LOCATION = "unix:///var/run/docker.sock";

@Override
public DockerClientConfig provideConfiguration()
throws InvalidConfigurationException {
DockerClientConfig config = new DockerClientConfig.DockerClientConfigBuilder().withUri(SOCKET_LOCATION).build();
DockerClient client = DockerClientBuilder.getInstance(config).build();

try {
client.pingCmd().exec();
} catch (Exception e) {
throw new InvalidConfigurationException("ping failed");
}

LOGGER.info("Accessing docker with local Unix socket");
return config;
}

@Override
public String getDescription() {
return "local Unix socket (" + SOCKET_LOCATION + ")";
}

}

0 comments on commit d25410d

Please sign in to comment.