本文整理汇总了Java中com.github.dockerjava.core.DockerClientConfig类的典型用法代码示例。如果您正苦于以下问题:Java DockerClientConfig类的具体用法?Java DockerClientConfig怎么用?Java DockerClientConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DockerClientConfig类属于com.github.dockerjava.core包,在下文中一共展示了DockerClientConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupDockerClient
import com.github.dockerjava.core.DockerClientConfig; //导入依赖的package包/类
private void setupDockerClient() throws
InvalidCredentialsException {
if (dockerClient != null) {
return;
}
final DockerClientConfig config = createClientConfig();
final DockerCmdExecFactory dockerCmdExecFactory = new JerseyDockerCmdExecFactory();
dockerClient = DockerClientBuilder.getInstance(config)
.withDockerCmdExecFactory(dockerCmdExecFactory)
.build();
// Check if client was successfully created
final AuthResponse response = dockerClient.authCmd().exec();
if (!response.getStatus().equalsIgnoreCase("Login Succeeded")) {
throw new InvalidCredentialsException("Could not create DockerClient");
}
}
示例2: getDefaultConnection
import com.github.dockerjava.core.DockerClientConfig; //导入依赖的package包/类
/**
* TODO delete and make method with serverId param after thinking about it
*
* @return default connection to system docker
*/
public DockerClient getDefaultConnection() {
return connections.computeIfAbsent(DEFAULT_CONNECTION, id -> {
DockerClientConfig config = null;
if (SystemUtils.IS_OS_MAC_OSX) {
config = DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost("unix:///var/run/docker.sock")
.build();
}
if (SystemUtils.IS_OS_LINUX) {
config = DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost("unix:///var/run/docker.sock")
.build();
}
if (SystemUtils.IS_OS_WINDOWS) {
config = DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost("tcp://localhost:2376")
.withDockerTlsVerify(true)
.withDockerTlsVerify("1")
.build();
}
return DockerClientBuilder.getInstance(config).build();
});
}
示例3: connect
import com.github.dockerjava.core.DockerClientConfig; //导入依赖的package包/类
/**
* connects to Docker daemon
*
* @throws Exception
*/
public void connect() throws Exception {
DockerClientConfig config = DockerClientConfig.createDefaultConfigBuilder()
.withVersion(Constants.DOCKER_API_VERSION)
.withUri(Configuration.getDockerUrl())
.build();
dockerClient = DockerClientBuilder.getInstance(config).build();
try {
Info info = dockerClient.infoCmd().exec();
LoggingService.logInfo(MODULE_NAME, "connected to docker daemon: " + info.getName());
} catch (Exception e) {
LoggingService.logInfo(MODULE_NAME, "connecting to docker failed: " + e.getClass().getName() + " - " + e.getMessage());
throw e;
}
}
示例4: tryConfiguration
import com.github.dockerjava.core.DockerClientConfig; //导入依赖的package包/类
@NotNull
protected DockerClientConfig tryConfiguration(String dockerHost) {
Path dockerSocketFile = Paths.get(DOCKER_SOCK_PATH);
Integer mode;
try {
mode = (Integer) Files.getAttribute(dockerSocketFile, "unix:mode");
} catch (IOException e) {
throw new InvalidConfigurationException("Could not find unix domain socket", e);
}
if ((mode & 0xc000) != SOCKET_FILE_MODE_MASK) {
throw new InvalidConfigurationException("Found docker unix domain socket but file mode was not as expected (expected: srwxr-xr-x). This problem is possibly due to occurrence of this issue in the past: https://github.com/docker/docker/issues/13121");
}
config = DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost(dockerHost)
.withDockerTlsVerify(false)
.build();
client = getClientForConfig(config);
final int timeout = Integer.parseInt(System.getProperty(PING_TIMEOUT_PROPERTY_NAME, PING_TIMEOUT_DEFAULT));
ping(client, timeout);
return config;
}
示例5: init
import com.github.dockerjava.core.DockerClientConfig; //导入依赖的package包/类
@Override
public void init(DockerClientConfig dockerClientConfig) {
checkNotNull(dockerClientConfig, "config was not specified");
this.dockerClientConfig = dockerClientConfig;
bootstrap = new Bootstrap();
String scheme = dockerClientConfig.getDockerHost().getScheme();
if ("unix".equals(scheme)) {
nettyInitializer = new UnixDomainSocketInitializer();
} else if ("tcp".equals(scheme)) {
nettyInitializer = new InetSocketInitializer();
}
eventLoopGroup = nettyInitializer.init(bootstrap, dockerClientConfig);
baseResource = new WebTarget(channelProvider).path(dockerClientConfig.getApiVersion().asWebPathPart());
}
示例6: DockerCompose
import com.github.dockerjava.core.DockerClientConfig; //导入依赖的package包/类
public DockerCompose() {
DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost("unix:///var/run/docker.sock")
.build();
dockerClient = DockerClientBuilder.getInstance(config).build();
}
示例7: createDockerClientConfig
import com.github.dockerjava.core.DockerClientConfig; //导入依赖的package包/类
/**
* Creates a DockerClientConfig object to be used when creating the Java Docker client using a secured connection.
* @param host - Docker host address (IP) to connect to
* @param registryServerUrl - address of the private container registry
* @param username - user name to connect with to the private container registry
* @param password - password to connect with to the private container registry
* @param caPemContent - content of the ca.pem certificate file
* @param keyPemContent - content of the key.pem certificate file
* @param certPemContent - content of the cert.pem certificate file
* @return an instance of DockerClient configuration
*/
public static DockerClientConfig createDockerClientConfig(String host, String registryServerUrl, String username, String password,
String caPemContent, String keyPemContent, String certPemContent) {
return DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost(host)
.withDockerTlsVerify(true)
.withCustomSslConfig(new DockerSSLConfig(caPemContent, keyPemContent, certPemContent))
.withRegistryUrl(registryServerUrl)
.withRegistryUsername(username)
.withRegistryPassword(password)
.build();
}
示例8: getDockerClient
import com.github.dockerjava.core.DockerClientConfig; //导入依赖的package包/类
@Bean
public DockerClient getDockerClient () {
logger.info( "Creating pooled docker: {} ", docker.toString() );
DockerClient client = null;
try {
DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost( docker.getUrl() )
.build();
DockerCmdExecFactory dockerCmdExecFactory = new JerseyDockerCmdExecFactory()
.withReadTimeout( docker.getReadTimeoutSeconds() *1000 )
.withConnectTimeout( docker.getConnectionTimeoutSeconds() *1000 )
.withMaxTotalConnections( docker.getConnectionPool() )
.withMaxPerRouteConnections( 3 );
// DockerCmdExecFactory dockerCmdExecFactory = new NettyDockerCmdExecFactory()
// .withConnectTimeout( docker.getReadTimeoutSeconds() *1000 ) ;
client = DockerClientBuilder
.getInstance( config )
.withDockerCmdExecFactory( dockerCmdExecFactory )
.build();
// client = DefaultDockerClient.builder()
// .uri( docker.getUrl() )
// .connectionPoolSize( docker.getConnectionPool() )
// .build();
} catch (Throwable t) {
logger.warn( "Failed connecting to docker: {}", CSAP.getCsapFilteredStackTrace( t ) );
}
return client;
}
示例9: getDockerClient
import com.github.dockerjava.core.DockerClientConfig; //导入依赖的package包/类
@Override
public DockerClient getDockerClient() {
if (dockerClient == null) {
ConfigProperties configProperties = configurationCommands.getConfigProperties();
DockerClientConfig dockerConfig = DockerClientConfig
.createDefaultConfigBuilder()
.withUri(configProperties.getDockerHostProperty().getString())
.withDockerCertPath(configProperties.getCertPathProperty().getString()).build();
dockerClient = DockerClientBuilder.getInstance(dockerConfig).build();
}
return dockerClient;
}
示例10: createContainer
import com.github.dockerjava.core.DockerClientConfig; //导入依赖的package包/类
public static ClosableContainer createContainer(String containerName) throws Exception {
hostBuildDir = new File("./build/").getCanonicalPath();
File buildLogDir = new File(hostBuildDir, "log/");
if (!buildLogDir.exists() && !buildLogDir.mkdirs()) {
throw new IllegalStateException("fail to create buildLogDir:" + buildLogDir);
}
DefaultDockerClientConfig.Builder builder
= DefaultDockerClientConfig.createDefaultConfigBuilder().withApiVersion("1.12");
Optional<String> dockerHostEnv = Optional.ofNullable(System.getenv("DOCKER_HOST"));
builder.withDockerHost(dockerHostEnv.orElse("unix:///var/run/docker.sock"));
DockerClientConfig config = builder.build();
DockerClientBuilder dockerClientBuilder = DockerClientBuilder.getInstance(config);
dockerClientBuilder.withDockerCmdExecFactory(new DockerCmdExecFactoryImpl());
DockerClient dockerClient = dockerClientBuilder.build();
ClosableContainer.removeIfExists(dockerClient, containerName);
Ports portBindings = new Ports();
List<ExposedPort> ports = Arrays.asList(15050, 15051, RETZ_PORT, 9999).stream()
.map(port -> ExposedPort.tcp(port)).collect(Collectors.toList());
ports.forEach(port -> portBindings.bind(port, Ports.Binding.bindPort(port.getPort())));
Volume containerBuildDir = new Volume("/build");
CreateContainerCmd createCmd = dockerClient.createContainerCmd(IMAGE_NAME)
.withName(containerName)
.withPrivileged(true) // To use SystemD/Cgroups
.withExposedPorts(ports)
.withPortBindings(portBindings)
.withBinds(new Bind(hostBuildDir, containerBuildDir));
return ClosableContainer.createContainer(dockerClient, createCmd);
}
示例11: createClient
import com.github.dockerjava.core.DockerClientConfig; //导入依赖的package包/类
private DockerClient createClient() {
DockerClientConfig config = DockerClientConfig.createDefaultConfigBuilder()
.build();
DockerClient docker = DockerClientBuilder.getInstance(config)
.withDockerCmdExecFactory(this.commandExecFactory).build();
return docker;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:8,代码来源:SysVinitLaunchScriptIT.java
示例12: init
import com.github.dockerjava.core.DockerClientConfig; //导入依赖的package包/类
public void init() {
if (dc == null) {
DockerClientConfig.DockerClientConfigBuilder builder = DockerClientConfig.createDefaultConfigBuilder();
DockerClientConfig config = builder.build();
dc = DockerClientBuilder.getInstance(config).build();
dc.pullImageCmd(imageName).withTag(imageVersion).exec(new PullImageResultCallback()).awaitSuccess();
}
if (dockerPool == null) {
dockerPool = Executors.newFixedThreadPool(poolSize);
}
}
示例13: tryCreate
import com.github.dockerjava.core.DockerClientConfig; //导入依赖的package包/类
/**
* Tries to create a new instance of a {@link DockerClient} using the provided connection
* definition and configuration.
*
* If the provided settings do not successfully connect to Docker than an empty {@link Optional}
* is returned.
*
* @param connection the connedtion definition to use.
* @param config the config to use.
* @return an optional containing a docker client if the connection was successful.
*/
public Optional<DockerClient> tryCreate(Connect.Def connection, Config config) {
if (connection.resolve().isEmpty()) {
return Optional.empty();
}
DockerClientConfig instanceConfig = buildClientConfig(connection, config);
DockerClient client = DockerClientBuilder.getInstance(instanceConfig).withDockerCmdExecFactory(cmdExecFactory).build();
if (tryClient(client)) {
return Optional.of(client);
}
return Optional.empty();
}
示例14: buildClientConfig
import com.github.dockerjava.core.DockerClientConfig; //导入依赖的package包/类
private DockerClientConfig buildClientConfig(Connect.Def connection, Config config) {
DefaultDockerClientConfig.Builder configBuilder = DefaultDockerClientConfig.createDefaultConfigBuilder().withDockerHost(connection.resolve());
config.getDockerTlsVerify().resolve().ifPresent(value -> configBuilder.withDockerTlsVerify(value));
config.getDockerCertPath().resolve().ifPresent(value -> configBuilder.withDockerCertPath(value));
config.getDockerConfig().resolve().ifPresent(value -> configBuilder.withDockerConfig(value));
config.getApiVersion().ifPresent(value -> configBuilder.withApiVersion(value));
config.getRegistryUrl().ifPresent(value -> configBuilder.withRegistryUrl(value));
config.getRegistryUsername().ifPresent(value -> configBuilder.withRegistryUsername(value));
config.getRegistryPassword().ifPresent(value -> configBuilder.withRegistryPassword(value));
config.getRegistryEmail().ifPresent(value -> configBuilder.withRegistryEmail(value));
return configBuilder.build();
}
示例15: getObject
import com.github.dockerjava.core.DockerClientConfig; //导入依赖的package包/类
public DockerClient getObject() throws Exception {
DockerClientConfig config = DockerClientConfig.createDefaultConfigBuilder()
.withVersion(version)
.withUri(uri)
.withUsername(username)
.withPassword(password)
.withEmail(email)
.withServerAddress(serverAddress)
.withDockerCertPath(dockerCertPath)
.build();
return DockerClientBuilder.getInstance(config).build();
}