Java Code Examples for com.spotify.docker.client.DefaultDockerClient#Builder
The following examples show how to use
com.spotify.docker.client.DefaultDockerClient#Builder .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DockerClientFactory.java From docker-swarm-elastic-agent-plugin with Apache License 2.0 | 6 votes |
private static DefaultDockerClient createClient(ClusterProfileProperties clusterProfileProperties) throws Exception { DefaultDockerClient.Builder builder = DefaultDockerClient.builder(); builder.uri(clusterProfileProperties.getDockerURI()); if (clusterProfileProperties.getDockerURI().startsWith("https://")) { setupCerts(clusterProfileProperties, builder); } if (clusterProfileProperties.useDockerAuthInfo()) { final RegistryAuth registryAuth = clusterProfileProperties.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; }
Example 2
Source File: DockerClientFactory.java From docker-swarm-elastic-agent-plugin with Apache License 2.0 | 6 votes |
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); } }
Example 3
Source File: DockerClientFactory.java From docker-elastic-agents-plugin with Apache License 2.0 | 6 votes |
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); } }
Example 4
Source File: DockerClientSpotify.java From doclipser with Eclipse Public License 1.0 | 6 votes |
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(); }
Example 5
Source File: AbstractDockerMojo.java From docker-maven-plugin with Apache License 2.0 | 6 votes |
protected DockerClient buildDockerClient() throws MojoExecutionException { final DefaultDockerClient.Builder builder; try { builder = getBuilder(); final String dockerHost = rawDockerHost(); if (!isNullOrEmpty(dockerHost)) { builder.uri(dockerHost); } final Optional<DockerCertificatesStore> certs = dockerCertificates(); if (certs.isPresent()) { builder.dockerCertificates(certs.get()); } } catch (DockerCertificateException ex) { throw new MojoExecutionException("Cannot build DockerClient due to certificate problem", ex); } builder.registryAuthSupplier(authSupplier()); return builder.build(); }
Example 6
Source File: DockerClientFactory.java From docker-elastic-agents-plugin with Apache License 2.0 | 5 votes |
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; if (pluginSettings.useCustomRegistryCredentials()) { auth = RegistryAuth.builder() .password(pluginSettings.getPrivateRegistryPassword()) .serverAddress(pluginSettings.getPrivateRegistryServer()) .username(pluginSettings.getPrivateRegistryUsername()) .build(); } else { auth = RegistryAuth.fromDockerConfig(pluginSettings.getPrivateRegistryServer()).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; }
Example 7
Source File: DockerContainerConfig.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
public static DefaultDockerClient.Builder defaultDockerClientBuilder() { DefaultDockerClient.Builder defaultClient = null; try { defaultClient = DefaultDockerClient.fromEnv(); } catch (DockerCertificateException e) { throw new RuntimeException(e); } return defaultClient; }
Example 8
Source File: DockerContainerConfig.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
public Builder withDockerClientBuilder(final DefaultDockerClient.Builder dockerClientBuilder) { this.dockerClientBuilder = dockerClientBuilder; return this; }
Example 9
Source File: DockerContainerConfig.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
public DefaultDockerClient.Builder getDockerClientBuilder() { return dockerClientBuilder; }
Example 10
Source File: PollingDockerClient.java From helios with Apache License 2.0 | 4 votes |
public PollingDockerClient(final DefaultDockerClient.Builder builder) { super(builder); }
Example 11
Source File: AbstractDockerMojo.java From docker-maven-plugin with Apache License 2.0 | 4 votes |
protected DefaultDockerClient.Builder getBuilder() throws DockerCertificateException { return DefaultDockerClient.fromEnv() .readTimeoutMillis(0); }
Example 12
Source File: AbstractDockerMojoTest.java From docker-maven-plugin with Apache License 2.0 | 4 votes |
@Override protected DefaultDockerClient.Builder getBuilder() throws DockerCertificateException { return builder; }