/** * Create a {@link DockerHost} from DOCKER_HOST and DOCKER_PORT env vars. * * @return The DockerHost object. */ public static DockerHost fromEnv() { final String host = endpointFromEnv(); final String certPath = certPathFromEnv(); return new DockerHost(host, certPath); }
final Path dockerCertPath = Paths.get(firstNonNull(DockerHost.certPathFromEnv(), DockerHost.defaultCertPath()));
/** * Create a {@link DockerHost} from DOCKER_HOST and DOCKER_PORT env vars. * * @return The DockerHost object. */ public static DockerHost fromEnv() { final String host = endpointFromEnv(); final String certPath = certPathFromEnv(); return new DockerHost(host, certPath); }
/** * 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; }