当前位置: 首页>>代码示例>>Java>>正文


Java DefaultDockerClientConfig类代码示例

本文整理汇总了Java中com.github.dockerjava.core.DefaultDockerClientConfig的典型用法代码示例。如果您正苦于以下问题:Java DefaultDockerClientConfig类的具体用法?Java DefaultDockerClientConfig怎么用?Java DefaultDockerClientConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DefaultDockerClientConfig类属于com.github.dockerjava.core包,在下文中一共展示了DefaultDockerClientConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDockerClient

import com.github.dockerjava.core.DefaultDockerClientConfig; //导入依赖的package包/类
private DockerClient getDockerClient() {
    /*
    TLS connection: ...

    DefaultDockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
            .withDockerHost("tcp://192.168.99.100:2376")
            .withDockerTlsVerify(true)
            .withDockerCertPath("/Users/jon/.docker/machine/machines/default")
            .build();
    */

    final String localDockerHost = SystemUtils.IS_OS_WINDOWS ? "tcp://localhost:2375" : "unix:///var/run/docker.sock";

    final DefaultDockerClientConfig config = DefaultDockerClientConfig
            .createDefaultConfigBuilder()
            .withDockerHost(localDockerHost)
            .build();

    return DockerClientBuilder
            .getInstance(config)
            .build();
}
 
开发者ID:jonfryd,项目名称:tifoon,代码行数:23,代码来源:DockerExecutorPlugin.java

示例2: getDefaultConnection

import com.github.dockerjava.core.DefaultDockerClientConfig; //导入依赖的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();
    });
}
 
开发者ID:petrleocompel,项目名称:docker-dash,代码行数:31,代码来源:DockerConnectionService.java

示例3: init

import com.github.dockerjava.core.DefaultDockerClientConfig; //导入依赖的package包/类
public static void init() {
  DefaultDockerClientConfig conf = DefaultDockerClientConfig
      .createDefaultConfigBuilder()
      .withRegistryUrl("https://index.docker.io/v1/").build();

  dockerClient =
      DockerClientBuilder.getInstance(conf).withDockerCmdExecFactory(new NettyDockerCmdExecFactory()).build();
  try {
    dockerClient.inspectImageCmd("busybox").exec();
  } catch (Exception e) {
    LOGGER.info("Pulling image 'busybox'");
    // need to block until image is pulled completely
    dockerClient.pullImageCmd("busybox").withTag("latest").exec(new PullImageResultCallback()).awaitSuccess();
  }

  String logRecord = "This is magic string keyToFind=42 and some text at the end";
  container = dockerClient.createContainerCmd("busybox")
      .withCmd("/bin/sh", "-c", "while true; do echo " + logRecord + "; sleep 1; done")
      .withTty(true)
      .exec();

  dockerClient.startContainerCmd(container.getId()).exec();
}
 
开发者ID:scalecube,项目名称:docker-utils,代码行数:24,代码来源:LogParsingTest.java

示例4: tryConfiguration

import com.github.dockerjava.core.DefaultDockerClientConfig; //导入依赖的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;
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:27,代码来源:UnixSocketClientProviderStrategy.java

示例5: createDockerClient

import com.github.dockerjava.core.DefaultDockerClientConfig; //导入依赖的package包/类
private static DockerClient createDockerClient(String dockerUrl, String dockerVersion, String dockerCertPath,
                                               AuthConfig authConfig) {
    // TODO JENKINS-26512
    SSLConfig dummySSLConf = (new SSLConfig() {
        public SSLContext getSSLContext() throws KeyManagementException, UnrecoverableKeyException,
                NoSuchAlgorithmException, KeyStoreException {
            return null;
        }
    });

    if (dockerCertPath != null) {
        dummySSLConf = new LocalDirectorySSLConfig(dockerCertPath);
    }
    
    DefaultDockerClientConfig.Builder configBuilder = new DefaultDockerClientConfig.Builder().withDockerHost(dockerUrl)
            .withApiVersion(dockerVersion).withCustomSslConfig(dummySSLConf);
    if (authConfig != null) {
        configBuilder.withRegistryUsername(authConfig.getUsername())
                .withRegistryEmail(authConfig.getEmail())
                .withRegistryPassword(authConfig.getPassword())
                .withRegistryUrl(authConfig.getRegistryAddress());
    }
    // using jaxrs/jersey implementation here (netty impl is also available)
    DockerCmdExecFactory dockerCmdExecFactory = new DockerCmdExecFactoryImpl()
            .withConnectTimeout(1000)
            .withMaxTotalConnections(1)
            .withMaxPerRouteConnections(1);
    return DockerClientBuilder.getInstance(configBuilder).withDockerCmdExecFactory(dockerCmdExecFactory).build();
}
 
开发者ID:jenkinsci,项目名称:docker-build-step-plugin,代码行数:30,代码来源:DockerBuilder.java

示例6: createDockerClient

import com.github.dockerjava.core.DefaultDockerClientConfig; //导入依赖的package包/类
/**
 * Creates a Docker client from target properties.
 * @param targetProperties a non-null map
 * @return a Docker client
 * @throws TargetException if something went wrong
 */
public static DockerClient createDockerClient( Map<String,String> targetProperties ) throws TargetException {

	// Validate what needs to be validated.
	Logger logger = Logger.getLogger( DockerHandler.class.getName());
	logger.fine( "Setting the target properties." );

	String edpt = targetProperties.get( DockerHandler.ENDPOINT );
	if( Utils.isEmptyOrWhitespaces( edpt ))
		edpt = DockerHandler.DEFAULT_ENDPOINT;

	// The configuration is straight-forward.
	Builder config =
			DefaultDockerClientConfig.createDefaultConfigBuilder()
			.withDockerHost( edpt )
			.withRegistryUsername( targetProperties.get( DockerHandler.USER ))
			.withRegistryPassword( targetProperties.get( DockerHandler.PASSWORD ))
			.withRegistryEmail( targetProperties.get( DockerHandler.EMAIL ))
			.withApiVersion( targetProperties.get( DockerHandler.VERSION ));

	// Build the client.
	DockerClientBuilder clientBuilder = DockerClientBuilder.getInstance( config.build());

	return clientBuilder.build();
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:31,代码来源:DockerUtils.java

示例7: testNettyDockerCmdExecFactoryConfigWithoutApiVersion

import com.github.dockerjava.core.DefaultDockerClientConfig; //导入依赖的package包/类
@Test
public void testNettyDockerCmdExecFactoryConfigWithoutApiVersion() throws Exception {
    int dockerPort = getFreePort();

    NettyDockerCmdExecFactory factory = new NettyDockerCmdExecFactory();
    Builder configBuilder = new DefaultDockerClientConfig.Builder()
        .withDockerTlsVerify(false)
        .withDockerHost("tcp://localhost:" + dockerPort);

    DockerClient client = DockerClientBuilder.getInstance(configBuilder)
        .withDockerCmdExecFactory(factory)
        .build();

    FakeDockerServer server = new FakeDockerServer(dockerPort);
    server.start();
    try {
        client.versionCmd().exec();

        List<HttpRequest> requests = server.getRequests();

        assertEquals(requests.size(), 1);
        assertEquals(requests.get(0).uri(), "/version");
    } finally {
        server.stop();
    }
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:27,代码来源:NettyDockerCmdExecFactoryConfigTest.java

示例8: getClient

import com.github.dockerjava.core.DefaultDockerClientConfig; //导入依赖的package包/类
public DockerClient getClient() {
    if (client == null) {
        final Integer readTimeoutInMillisecondsOrNull = readTimeout > 0 ? Integer.valueOf(readTimeout * 1000) : null;
        final Integer connectTimeoutInMillisecondsOrNull = connectTimeout > 0 ? Integer.valueOf(connectTimeout * 1000) : null;
        client = DockerClientBuilder.getInstance(
            new DefaultDockerClientConfig.Builder()
                .withDockerHost(dockerHost.getUri())
                .withCustomSslConfig(toSSlConfig(dockerHost.getCredentialsId()))
            )
            .withDockerCmdExecFactory(new NettyDockerCmdExecFactory()
            .withReadTimeout(readTimeoutInMillisecondsOrNull)
            .withConnectTimeout(connectTimeoutInMillisecondsOrNull))
            .build();
    }
    return client;
}
 
开发者ID:jenkinsci,项目名称:docker-plugin,代码行数:17,代码来源:DockerAPI.java

示例9: dockerStart

import com.github.dockerjava.core.DefaultDockerClientConfig; //导入依赖的package包/类
@Start
public void dockerStart() throws Exception {
    super.start();
    Log.info("DockerNode \"{}\" will update model based on local Docker engine every {}s", context.getNodeName(), update);
    DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder().build();
    this.docker = DockerClientBuilder.getInstance(config).build();

    this.modelListener = new AbstractModelListener() {
        @Override
        public void updateSuccess(UpdateContext context) {
            if (executorService == null) {
                executorService = Executors.newSingleThreadScheduledExecutor();
                executorService.scheduleAtFixedRate(DockerNode.this::updateModelAccordingToDocker, 0, update, TimeUnit.SECONDS);
            }
        }
    };
    this.modelService.registerModelListener(this.modelListener);
}
 
开发者ID:kevoree,项目名称:kevoree-library,代码行数:19,代码来源:DockerNode.java

示例10: DockerCompose

import com.github.dockerjava.core.DefaultDockerClientConfig; //导入依赖的package包/类
public DockerCompose() {
    DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
            .withDockerHost("unix:///var/run/docker.sock")
            .build();

    dockerClient = DockerClientBuilder.getInstance(config).build();

}
 
开发者ID:mcafee,项目名称:management-sdk-for-kafka,代码行数:9,代码来源:DockerCompose.java

示例11: createDockerClientConfig

import com.github.dockerjava.core.DefaultDockerClientConfig; //导入依赖的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();
}
 
开发者ID:Azure-Samples,项目名称:acr-java-manage-azure-container-registry,代码行数:23,代码来源:DockerUtils.java

示例12: getDockerClient

import com.github.dockerjava.core.DefaultDockerClientConfig; //导入依赖的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;
	}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:35,代码来源:CsapCoreService.java

示例13: newDockerClient

import com.github.dockerjava.core.DefaultDockerClientConfig; //导入依赖的package包/类
private DockerClient newDockerClient(final String dockerSocket, final String dockerRegistry) {
    val dockerConfig = DefaultDockerClientConfig.createDefaultConfigBuilder()
            .withDockerHost(dockerSocket)
            .withDockerTlsVerify(VERIFY_TLS)
            .withApiVersion(API_VERSION)
            .withRegistryUrl(dockerRegistry)
            .build();

    return DockerClientBuilder.getInstance(dockerConfig).build();
}
 
开发者ID:fabzo,项目名称:kraken,代码行数:11,代码来源:DockerCommands.java

示例14: createContainer

import com.github.dockerjava.core.DefaultDockerClientConfig; //导入依赖的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);
}
 
开发者ID:retz,项目名称:retz,代码行数:35,代码来源:IntTestBase.java

示例15: getClient

import com.github.dockerjava.core.DefaultDockerClientConfig; //导入依赖的package包/类
public static DockerClient getClient(){
    DefaultDockerClientConfig config = DefaultDockerClientConfig
            .createDefaultConfigBuilder()
            // FIXME: Modularize: Don't count on a particular IP address and file system
            //.withDockerHost("tcp://192.168.99.100:2376")
            //.withDockerCertPath(USER_HOME + "/.docker/machine/certs")
            .build();

    return DockerClientBuilder
            .getInstance(config)
            .build();
}
 
开发者ID:b-long,项目名称:jedi,代码行数:13,代码来源:DockerClientFacade.java


注:本文中的com.github.dockerjava.core.DefaultDockerClientConfig类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。