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


Java DockerClientBuilder类代码示例

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


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

示例1: setupDockerClient

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

示例2: getDockerClient

import com.github.dockerjava.core.DockerClientBuilder; //导入依赖的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

示例3: buildDockerClientWithShutdown

import com.github.dockerjava.core.DockerClientBuilder; //导入依赖的package包/类
private DockerClient buildDockerClientWithShutdown () {

		logger.warn( "\n\n\n *********** Dockerclient: {} poolsize: {}  *** \n\n\n", 
			dockerConfiguration.getDockerHost(), dockerPoolSize );

		// need to support connection leaks in docker java image load code
		// means shutdown needs to occur - which can then cause intermittent
		// race conditions.
		//
		if ( lastFactory != null ) {
			try {
				lastFactory.close();
			} catch (IOException e) {
				logger.error( "Failed closing factory", e );
			}
		}
		// Netty: use 2*core count threads
		// lastFactory = buildNettyDockerCommandFactory() ;
		lastFactory = buildDockerJerseyCommandFactory();
		return DockerClientBuilder
			.getInstance( dockerConfiguration )
			.withDockerCmdExecFactory( lastFactory )
			.build();
	}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:25,代码来源:Docker_Java.java

示例4: getDefaultConnection

import com.github.dockerjava.core.DockerClientBuilder; //导入依赖的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

示例5: setUp

import com.github.dockerjava.core.DockerClientBuilder; //导入依赖的package包/类
@Before
public void setUp() {
  init();

  client = DockerClientBuilder.getInstance().build();
  List<Container> running = client.listContainersCmd().withStatusFilter("running").exec();
  if (running != null) {
    running.forEach(container -> client.stopContainerCmd(container.getId()).exec());
  }

  vertx = Vertx.vertx();
  discovery = ServiceDiscovery.create(vertx);
  bridge = new DockerServiceImporter();
  discovery.registerServiceImporter(bridge,
      new JsonObject().put("scan-period", -1));

  await().until(() -> bridge.started);
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:19,代码来源:DockerBridgeTest.java

示例6: init

import com.github.dockerjava.core.DockerClientBuilder; //导入依赖的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

示例7: connect

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

示例8: removeContainer

import com.github.dockerjava.core.DockerClientBuilder; //导入依赖的package包/类
public void removeContainer(Server server) throws Exception {
    DockerClient dockerClient = DockerClientBuilder.getInstance("http://" + server.getNode().getPrivateAddress() + ":4243").build();

    for (Container container : dockerClient.listContainersCmd().withShowAll(true).exec()) {
        String name = container.getNames()[0];
        if (name.equals("/" + server.getServerType().getName() + "." + server.getNumber())) {
            log.info("Deleting " + Arrays.toString(container.getNames()));
            try {
                dockerClient.killContainerCmd(container.getId()).exec();
            } catch (Exception ignored) {
            }
            dockerClient.removeContainerCmd(container.getId()).withForce(true).exec();
            break;
        }
    }
}
 
开发者ID:Minestack,项目名称:Redstone-Old,代码行数:17,代码来源:ServerManager.java

示例9: removeContainer

import com.github.dockerjava.core.DockerClientBuilder; //导入依赖的package包/类
public void removeContainer(Bungee bungee) {
    DockerClient dockerClient = DockerClientBuilder.getInstance("http://" + bungee.getNode().getPrivateAddress() + ":4243").build();

    for (Container container : dockerClient.listContainersCmd().withShowAll(true).exec()) {
        String name = container.getNames()[0];
        if (name.equals("/" + bungee.getBungeeType().getName()+"."+bungee.getPublicAddress().getPublicAddress()) || name.contains(bungee.getPublicAddress().getPublicAddress())) {
            log.info("Deleting " + Arrays.toString(container.getNames()));
            try {
                dockerClient.killContainerCmd(container.getId()).exec();
            } catch (Exception ignored) {
            }
            dockerClient.removeContainerCmd(container.getId()).withForce(true).exec();
            break;
        }
    }
}
 
开发者ID:Minestack,项目名称:Redstone-Old,代码行数:17,代码来源:BungeeManager.java

示例10: createDockerClient

import com.github.dockerjava.core.DockerClientBuilder; //导入依赖的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

示例11: createDockerClient

import com.github.dockerjava.core.DockerClientBuilder; //导入依赖的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

示例12: getDockerClient

import com.github.dockerjava.core.DockerClientBuilder; //导入依赖的package包/类
@VsoMethod(showInApi = false)
public DockerClient getDockerClient()
{
	DockerClient dockerClient = null;
	try
	{
		configureNode();
		dockerClient = DockerClientBuilder.getInstance(config).withServiceLoaderClassLoader(CooptoPluginAdaptor.class.getClassLoader()).build();
		
	}
	catch (Exception e)
	{
		final StringWriter sw = new StringWriter();
		final PrintWriter pw = new PrintWriter(sw, true);
		e.printStackTrace(pw);
		log.error("Error while creating Docker client. Details:\n" + sw.getBuffer().toString());
	}

	return dockerClient;
}
 
开发者ID:m451,项目名称:coopto,代码行数:21,代码来源:DockerNode.java

示例13: getClient

import com.github.dockerjava.core.DockerClientBuilder; //导入依赖的package包/类
public DockerClient getClient() {
    if (cmdIT.getFactoryType() == NETTY) {
        if (nettyClient == null) {
            nettyClient = DockerClientBuilder.getInstance(config())
                    .withDockerCmdExecFactory((new NettyDockerCmdExecFactory())
                            .withConnectTimeout(10 * 1000))
                    .build();
        }

        return nettyClient;
    } else if (cmdIT.getFactoryType() == JERSEY) {
        if (jerseyClient == null) {
            jerseyClient = DockerClientBuilder.getInstance(config())
                    .withDockerCmdExecFactory((new JerseyDockerCmdExecFactory())
                            .withConnectTimeout(10 * 1000))
                    .build();
        }
        return jerseyClient;
    }

    throw new IllegalStateException("Why factory type is not set?");
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:23,代码来源:DockerRule.java

示例14: testNettyDockerCmdExecFactoryConfigWithoutApiVersion

import com.github.dockerjava.core.DockerClientBuilder; //导入依赖的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

示例15: getClient

import com.github.dockerjava.core.DockerClientBuilder; //导入依赖的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


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