Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
35 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
32 changes: 32 additions & 0 deletions
32
core/src/main/java/org/testcontainers/dockerclient/UnixSocketConfigurationStrategy.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,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 + ")"; | ||
} | ||
|
||
} |