builder.dockerCertificates(certs.get());
private DockerClient createDockerClient(final AgentConfig config) throws IOException { final DefaultDockerClient.Builder builder = DefaultDockerClient.builder() .uri(config.getDockerHost().uri()); if (config.getConnectionPoolSize() != -1) { builder.connectionPoolSize(config.getConnectionPoolSize()); } if (!isNullOrEmpty(config.getDockerHost().dockerCertPath())) { final Path dockerCertPath = java.nio.file.Paths.get(config.getDockerHost().dockerCertPath()); final DockerCertificates dockerCertificates; try { dockerCertificates = new DockerCertificates(dockerCertPath); } catch (DockerCertificateException e) { throw new RuntimeException(e); } builder.dockerCertificates(dockerCertificates); } if (config.getGoogleCredentials() != null) { builder.registryAuthSupplier( ContainerRegistryAuthSupplier .forCredentials(config.getGoogleCredentials()) .build() ); } return new PollingDockerClient(builder); }
public static DockerClient buildClient(URI dockerHost, Path certificatesPath) { try { if (dockerHost == null) { logger.info("Configuring docker host from environment"); return DefaultDockerClient.fromEnv().build(); } else { logger.info("Configuring docker host from configuration"); DefaultDockerClient.Builder builder = DefaultDockerClient.builder().uri(dockerHost); if (certificatesPath != null) { builder.dockerCertificates(new DockerCertificates(certificatesPath)); } return builder.build(); } } catch (DockerCertificateException e) { logger.error("Could not read certificates", e); throw new IllegalArgumentException("Could not read certificates: " + e.getMessage()); } }
dockerBuilder.dockerCertificates(new SkipVerifyDockerCertificatesStore());
/** * Create a new {@link DefaultDockerClient} builder prepopulated with values loaded from the * DOCKER_HOST and DOCKER_CERT_PATH environment variables. * * @return Returns a builder that can be used to further customize and then build the client. * @throws DockerCertificateException if we could not build a DockerCertificates object */ public static Builder fromEnv() throws DockerCertificateException { final String endpoint = DockerHost.endpointFromEnv(); final Path dockerCertPath = Paths.get(firstNonNull(DockerHost.certPathFromEnv(), DockerHost.defaultCertPath())); final Builder builder = new Builder(); final Optional<DockerCertificatesStore> certs = DockerCertificates.builder() .dockerCertPath(dockerCertPath).build(); if (endpoint.startsWith(UNIX_SCHEME + "://")) { builder.uri(endpoint); } else { final String stripped = endpoint.replaceAll(".*://", ""); final HostAndPort hostAndPort = HostAndPort.fromString(stripped); final String hostText = hostAndPort.getHost(); final String scheme = certs.isPresent() ? "https" : "http"; final int port = hostAndPort.getPortOrDefault(DockerHost.defaultPort()); final String address = isNullOrEmpty(hostText) ? DockerHost.defaultAddress() : hostText; builder.uri(scheme + "://" + address + ":" + port); } if (certs.isPresent()) { builder.dockerCertificates(certs.get()); } return builder; }
/** * Create a new client with default configuration. * * @param uri The docker rest api uri. * @param dockerCertificatesStore The certificates to use for HTTPS. */ public DefaultDockerClient(final URI uri, final DockerCertificatesStore dockerCertificatesStore) { this(new Builder().uri(uri).dockerCertificates(dockerCertificatesStore)); }
/** * Create a new client with default configuration. * * @param uri The docker rest api uri. * @param dockerCertificatesStore The certificates to use for HTTPS. */ public DefaultDockerClient(final URI uri, final DockerCertificatesStore dockerCertificatesStore) { this(new Builder().uri(uri).dockerCertificates(dockerCertificatesStore)); }