當前位置: 首頁>>代碼示例>>Java>>正文


Java DefaultDockerClient類代碼示例

本文整理匯總了Java中com.spotify.docker.client.DefaultDockerClient的典型用法代碼示例。如果您正苦於以下問題:Java DefaultDockerClient類的具體用法?Java DefaultDockerClient怎麽用?Java DefaultDockerClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DefaultDockerClient類屬於com.spotify.docker.client包,在下文中一共展示了DefaultDockerClient類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createClient

import com.spotify.docker.client.DefaultDockerClient; //導入依賴的package包/類
private static DefaultDockerClient createClient(PluginSettings pluginSettings) throws Exception {
    DefaultDockerClient.Builder builder = DefaultDockerClient.builder();

    builder.uri(pluginSettings.getDockerURI());
    if (pluginSettings.getDockerURI().startsWith("https://")) {
        setupCerts(pluginSettings, builder);
    }

    if (pluginSettings.useDockerAuthInfo()) {
        RegistryAuth auth = RegistryAuth.builder()
                .password(pluginSettings.getPrivateRegistryPassword())
                .serverAddress(pluginSettings.getPrivateRegistryServer())
                .username(pluginSettings.getPrivateRegistryUsername())
                .build();
        builder.registryAuth(auth);
    }

    DefaultDockerClient docker = builder.build();
    String ping = docker.ping();
    if (!"OK".equals(ping)) {
        throw new RuntimeException("Could not ping the docker server, the server said '" + ping + "' instead of 'OK'.");
    }
    return docker;
}
 
開發者ID:gocd-contrib,項目名稱:docker-elastic-agents,代碼行數:25,代碼來源:DockerClientFactory.java

示例2: setupCerts

import com.spotify.docker.client.DefaultDockerClient; //導入依賴的package包/類
private static void setupCerts(PluginSettings pluginSettings, DefaultDockerClient.Builder builder) throws IOException, DockerCertificateException {
    if (isBlank(pluginSettings.getDockerCACert()) || isBlank(pluginSettings.getDockerClientCert()) || isBlank(pluginSettings.getDockerClientKey())) {
        LOG.warn("Missing docker certificates, will attempt to connect without certificates");
        return;
    }

    Path certificateDir = Files.createTempDirectory(UUID.randomUUID().toString());
    File tempDirectory = certificateDir.toFile();

    try {
        FileUtils.writeStringToFile(new File(tempDirectory, DockerCertificates.DEFAULT_CA_CERT_NAME), pluginSettings.getDockerCACert(), StandardCharsets.UTF_8);
        FileUtils.writeStringToFile(new File(tempDirectory, DockerCertificates.DEFAULT_CLIENT_CERT_NAME), pluginSettings.getDockerClientCert(), StandardCharsets.UTF_8);
        FileUtils.writeStringToFile(new File(tempDirectory, DockerCertificates.DEFAULT_CLIENT_KEY_NAME), pluginSettings.getDockerClientKey(), StandardCharsets.UTF_8);
        builder.dockerCertificates(new DockerCertificates(certificateDir));
    } finally {
        FileUtils.deleteDirectory(tempDirectory);
    }
}
 
開發者ID:gocd-contrib,項目名稱:docker-elastic-agents,代碼行數:19,代碼來源:DockerClientFactory.java

示例3: createClient

import com.spotify.docker.client.DefaultDockerClient; //導入依賴的package包/類
private static DefaultDockerClient createClient(PluginSettings pluginSettings) throws Exception {
    DefaultDockerClient.Builder builder = DefaultDockerClient.builder();

    builder.uri(pluginSettings.getDockerURI());
    if (pluginSettings.getDockerURI().startsWith("https://")) {
        setupCerts(pluginSettings, builder);
    }

    if (pluginSettings.useDockerAuthInfo()) {
        final RegistryAuth registryAuth = pluginSettings.registryAuth();
        LOG.info(format("Using private docker registry server `{0}`.", registryAuth.serverAddress()));
        builder.registryAuth(registryAuth);
    }

    DefaultDockerClient docker = builder.build();
    String ping = docker.ping();
    if (!"OK".equals(ping)) {
        throw new RuntimeException("Could not ping the docker server, the server said '" + ping + "' instead of 'OK'.");
    }
    return docker;
}
 
開發者ID:gocd-contrib,項目名稱:docker-swarm-elastic-agents,代碼行數:22,代碼來源:DockerClientFactory.java

示例4: EmbeddedPostgresDocker

import com.spotify.docker.client.DefaultDockerClient; //導入依賴的package包/類
private EmbeddedPostgresDocker(PostgresContainer postgresContainer) {
    try {
        this.imageConfig = postgresContainer;

        AuthConfig authConfig = AuthConfig.fromDockerConfig().build();

        this.dockerClient = DefaultDockerClient.fromEnv()
                .authConfig(authConfig)
                .build();

        dockerClient.pull(imageConfig.getContainerImage());
        this.container = createContainer(dockerClient, postgresContainer.getPostgresPort(), postgresContainer.getExposedPort());

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:intappx,項目名稱:junit-docker-postgres,代碼行數:18,代碼來源:EmbeddedPostgresDocker.java

示例5: DockerWrapper

import com.spotify.docker.client.DefaultDockerClient; //導入依賴的package包/類
/**
 * Constructor.
 * @param dockerHost String. The docker host ex: https://something:2376
 * @param certPath String. The certificate path
 * @param feedBackLevel String. The logging level: q = ERROR, v = DEBUG, i = info (default)
 * @throws DockerCertificateException
 */
public DockerWrapper(String dockerHost, String certPath, String feedBackLevel) throws DockerCertificateException {
	this.dockerHost = dockerHost;
	this.certPath = certPath;
	this.docker = DefaultDockerClient.builder()
		    .uri(URI.create(this.dockerHost))
		    .dockerCertificates(new DockerCertificates(Paths.get(this.certPath)))
		    .build();
	if (feedBackLevel.equalsIgnoreCase("q")) {
		Logger.getRootLogger().setLevel(Level.ERROR);
		logger.setLevel(Level.ERROR);
	}
	else if (feedBackLevel.equalsIgnoreCase("v")) {
			Logger.getRootLogger().setLevel(Level.DEBUG);
			logger.setLevel(Level.DEBUG);
	}
}
 
開發者ID:cleuton,項目名稱:servkeeper,代碼行數:24,代碼來源:DockerWrapper.java

示例6: createClient

import com.spotify.docker.client.DefaultDockerClient; //導入依賴的package包/類
private DefaultDockerClient createClient() {
    DefaultDockerClient dockerClient;
    Optional<DockerCertificates> certs = Optional.absent();
    if (mccySettings.getDockerCertPath() != null) {
        try {
            certs = DockerCertificates.builder()
                    .dockerCertPath(Paths.get(mccySettings.getDockerCertPath())).build();
        } catch (DockerCertificateException e) {
            throw new IllegalArgumentException("Unable to initialize Docker certificates with given configuration");
        }
    }

    final DefaultDockerClient.Builder clientBuilder = DefaultDockerClient.builder();

    if (certs.isPresent()) {
        clientBuilder
                .dockerCertificates(certs.get());
    }

    dockerClient = clientBuilder
            .uri(mccySettings.getDockerHostUri())
            .build();
    return dockerClient;
}
 
開發者ID:moorkop,項目名稱:mccy-engine,代碼行數:25,代碼來源:DockerClientProxyImpl.java

示例7: getDockerClient

import com.spotify.docker.client.DefaultDockerClient; //導入依賴的package包/類
public DockerClient getDockerClient() throws DockerCertificateException {
	DockerClient client = null;
	if (this.isUseDefault()) {
		client = DefaultDockerClient.builder()
				.uri(DefaultDockerClient.DEFAULT_UNIX_ENDPOINT).build();
	} else {
		if (this.isUseUnixSocket()) {
			client = DefaultDockerClient.builder().uri(getSocketPath())
					.build();
		} else if (isUseHTTPS()) {
			if (isEnableAuth()) {
				client = DefaultDockerClient
						.builder()
						.dockerCertificates(
								new DockerCertificates(Paths
										.get(getAuthPath())))
						.uri(getHost()).build();
			} else {
				client = DefaultDockerClient.builder().uri(getHost())
						.build();
			}
		}
	}
	return client;
}
 
開發者ID:osswangxining,項目名稱:dockerfoundry,代碼行數:26,代碼來源:DockerConnectionElement.java

示例8: DockerClientSpotify

import com.spotify.docker.client.DefaultDockerClient; //導入依賴的package包/類
public DockerClientSpotify() {
    messageConsole = new DockerClientMessageConsole(Constants.CONSOLE_NAME);
    dockerConfig = new DockerConfig();

    final String endpoint = dockerConfig.getUri();
    final String dockerCertPath = dockerConfig.getDockerCertPath();

    final DefaultDockerClient.Builder builder = new DefaultDockerClient.Builder();
    builder.uri(endpoint);
    builder.readTimeoutMillis(DefaultDockerClient.NO_TIMEOUT);

    if (dockerCertPath != null && !dockerCertPath.isEmpty()) {
        try {
            builder.dockerCertificates(new DockerCertificates(Paths
                    .get(dockerCertPath)));
        } catch (DockerCertificateException e) {
            messageConsole.getDockerConsoleOut().println(
                    "[ERROR] " + e.toString());
        }
    }

    dockerClient = builder.build();
}
 
開發者ID:domeide,項目名稱:doclipser,代碼行數:24,代碼來源:DockerClientSpotify.java

示例9: initialize

import com.spotify.docker.client.DefaultDockerClient; //導入依賴的package包/類
@Override
public void initialize(URI dockerConnectionURI) throws IOException {

  synchronized (this) {

    if (this.client != null) {
      return;
    }

    final URI dockerConnection =
        EoulsanRuntime.getSettings().getDockerConnectionURI();

    if (dockerConnection == null) {
      throw new IOException("Docker connection URI is not set. "
          + "Please set the \"main.docker.uri\" global parameter");
    }

    this.client = new DefaultDockerClient(dockerConnection);

    if (this.client == null) {
      throw new IOException("Unable to connect to Docker deamon: "
          + EoulsanRuntime.getSettings().getDockerConnection());
    }
  }
}
 
開發者ID:GenomicParisCentre,項目名稱:eoulsan,代碼行數:26,代碼來源:SpotifyDockerClient.java

示例10: randomlyPickOneMatchingElement

import com.spotify.docker.client.DefaultDockerClient; //導入依賴的package包/類
public Optional<Container> randomlyPickOneMatchingElement(final DefaultDockerClient dockerClient, final String key, final String value) throws DockerException, InterruptedException {
    final List<Container> containers = dockerClient.listContainers();

    final List<Container> collect = new ArrayList<>();
    for (Container container : containers) {
        final ContainerInfo containerInfo = dockerClient.inspectContainer(container.id());
        boolean res;
        res = containsKeyAndValue(containerInfo.config().env(), key, value);
        if (res) {
            collect.add(container);
        }

    }
    final Optional<Container> ret;
    if (collect.isEmpty()) {
        ret = Optional.empty();
    } else {
        ret = Optional.of(collect.get(random.nextInt(collect.size())));
    }
    return ret;
}
 
開發者ID:kevoree,項目名稱:kevoree-library,代碼行數:22,代碼來源:DockerKillerService.java

示例11: createDockerClient

import com.spotify.docker.client.DefaultDockerClient; //導入依賴的package包/類
static DockerClient createDockerClient() {
  try {
    return DefaultDockerClient.fromEnv().build();
  } catch (DockerCertificateException e) {
    throw Throwables.propagate(e);
  }
}
 
開發者ID:spotify,項目名稱:hype,代碼行數:8,代碼來源:DockerRunner.java

示例12: givenStartedContainer

import com.spotify.docker.client.DefaultDockerClient; //導入依賴的package包/類
@Given("^started floodlight container")
public void givenStartedContainer() throws Exception {
    TestUtils.clearEverything();
    dockerClient = DefaultDockerClient.fromEnv().build();
    floodlightContainer = dockerClient.listContainers()
            .stream()
            .filter(container ->
                    container.image().startsWith(FLOODLIGHT_CONTAINER_PREFIX))
            .findFirst().orElseThrow(() -> new IllegalStateException("Floodlight controller should be active"));
    assertNotNull(floodlightContainer);
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:12,代碼來源:ClearTablesTest.java

示例13: init

import com.spotify.docker.client.DefaultDockerClient; //導入依賴的package包/類
@Override
public void init() throws Exception {
    Assume.assumeTrue(DockerTestUtils.isDockerAvailable());

    this.creds = new DockerRegistryCredentials(
        "127.0.0.1:5000",
        "",
        "",
        "testing"
    );

    DockerClient client = DefaultDockerClient.fromEnv().build();
    logger.info("Downloading registry image");
    client.pull("registry:2");

    final Map<String, List<PortBinding>> ports = singletonMap(
        "5000/tcp", Collections.singletonList(PortBinding.of("0.0.0.0", 5000)));
    final HostConfig hostConfig = HostConfig.builder().portBindings(ports)
        .build();

    logger.info("Creating Local Registry Container");
    ContainerConfig config = ContainerConfig.builder()
        .hostConfig(hostConfig)
        .image("registry:2").build();
    String id = client.createContainer(config).id();
    logger.info("Registry container id: {}", id);

    logger.info("Starting registry container");
    client.startContainer(id);
    this.registryid = id;
}
 
開發者ID:StuPro-TOSCAna,項目名稱:TOSCAna,代碼行數:32,代碼來源:PushingImageBuilderIT.java

示例14: validate

import com.spotify.docker.client.DefaultDockerClient; //導入依賴的package包/類
@Override
public void validate(String tag) throws Exception {
    DockerClient client = DefaultDockerClient.fromEnv().authConfig(creds.toAuthConfig()).build();
    client.removeImage(tag);
    //Pull the image from the registry
    client.pull(tag);
}
 
開發者ID:StuPro-TOSCAna,項目名稱:TOSCAna,代碼行數:8,代碼來源:PushingImageBuilderIT.java

示例15: tearDown

import com.spotify.docker.client.DefaultDockerClient; //導入依賴的package包/類
@After
public void tearDown() throws Exception {
    DockerClient client = DefaultDockerClient.fromEnv().build();
    logger.info("Stopping and removing registry");
    client.killContainer(this.registryid);
    client.removeContainer(this.registryid);
}
 
開發者ID:StuPro-TOSCAna,項目名稱:TOSCAna,代碼行數:8,代碼來源:PushingImageBuilderIT.java


注:本文中的com.spotify.docker.client.DefaultDockerClient類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。