static int portFromEnv() { final String port = systemDelegate.getenv("DOCKER_PORT"); if (port == null) { return defaultPort(); } try { return Integer.parseInt(port); } catch (NumberFormatException e) { return defaultPort(); } }
static String defaultDockerEndpoint() { final String osName = systemDelegate.getProperty("os.name"); final String os = osName.toLowerCase(Locale.ENGLISH); if (os.equalsIgnoreCase("linux") || os.contains("mac")) { return DEFAULT_UNIX_ENDPOINT; } else if (System.getProperty("os.name").equalsIgnoreCase("Windows 10")) { //from Docker doc: Windows 10 64bit: Pro, Enterprise or Education return DEFAULT_WINDOWS_ENDPOINT; } else { return DEFAULT_ADDRESS + ":" + defaultPort(); } }
private DockerHost(final String endpoint, final String certPath) { if (endpoint.startsWith("unix://")) { this.port = 0; this.address = DEFAULT_ADDRESS; this.host = endpoint; this.uri = URI.create(endpoint); this.bindUri = URI.create(endpoint); } else { final String stripped = endpoint.replaceAll(".*://", ""); final HostAndPort hostAndPort = HostAndPort.fromString(stripped); final String hostText = hostAndPort.getHost(); final String scheme = isNullOrEmpty(certPath) ? "http" : "https"; this.port = hostAndPort.getPortOrDefault(defaultPort()); this.address = isNullOrEmpty(hostText) ? DEFAULT_ADDRESS : hostText; this.host = address + ":" + port; this.uri = URI.create(scheme + "://" + address + ":" + port); this.bindUri = URI.create("tcp://" + address + ":" + port); } this.certPath = certPath; }
final String scheme = certs.isPresent() ? "https" : "http"; final int port = hostAndPort.getPortOrDefault(DockerHost.defaultPort()); final String address = isNullOrEmpty(hostText) ? DockerHost.defaultAddress() : hostText;
static int portFromEnv() { final String port = systemDelegate.getenv("DOCKER_PORT"); if (port == null) { return defaultPort(); } try { return Integer.parseInt(port); } catch (NumberFormatException e) { return defaultPort(); } }
static String defaultDockerEndpoint() { final String osName = systemDelegate.getProperty("os.name"); final String os = osName.toLowerCase(Locale.ENGLISH); if (os.equalsIgnoreCase("linux") || os.contains("mac")) { return DEFAULT_UNIX_ENDPOINT; } else { return DEFAULT_ADDRESS + ":" + defaultPort(); } }
private DockerHost(final String endpoint, final String certPath) { if (endpoint.startsWith("unix://")) { this.port = 0; this.address = DEFAULT_ADDRESS; this.host = endpoint; this.uri = URI.create(endpoint); this.bindUri = URI.create(endpoint); } else { final String stripped = endpoint.replaceAll(".*://", ""); final HostAndPort hostAndPort = HostAndPort.fromString(stripped); final String hostText = hostAndPort.getHost(); final String scheme = isNullOrEmpty(certPath) ? "http" : "https"; this.port = hostAndPort.getPortOrDefault(defaultPort()); this.address = isNullOrEmpty(hostText) ? DEFAULT_ADDRESS : hostText; this.host = address + ":" + port; this.uri = URI.create(scheme + "://" + address + ":" + port); this.bindUri = URI.create("tcp://" + address + ":" + port); } this.certPath = 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; }