com.spotify.docker.client.DefaultDockerClient Java Examples

The following examples show how to use com.spotify.docker.client.DefaultDockerClient. 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: DockerService.java    From selenium-jupiter with Apache License 2.0 6 votes vote down vote up
public DockerService(Config config, InternalPreferences preferences) {
    this.config = config;
    this.preferences = preferences;

    dockerDefaultSocket = getConfig().getDockerDefaultSocket();
    dockerWaitTimeoutSec = getConfig().getDockerWaitTimeoutSec();
    dockerPollTimeMs = getConfig().getDockerPollTimeMs();

    String dockerServerUrl = getConfig().getDockerServerUrl();
    Builder dockerClientBuilder = null;
    if (dockerServerUrl.isEmpty()) {
        try {
            dockerClientBuilder = DefaultDockerClient.fromEnv();
        } catch (DockerCertificateException e) {
            throw new SeleniumJupiterException(e);
        }
    } else {
        log.debug("Using Docker server URL {}", dockerServerUrl);
        dockerClientBuilder = DefaultDockerClient.builder()
                .uri(dockerServerUrl);
    }
    dockerClient = dockerClientBuilder.build();
}
 
Example #2
Source File: DockerClientFactory.java    From docker-swarm-elastic-agent-plugin with Apache License 2.0 6 votes vote down vote up
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 #3
Source File: DockerClientFactory.java    From docker-swarm-elastic-agent-plugin with Apache License 2.0 6 votes vote down vote up
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: DockerClientFactory.java    From docker-elastic-agents-plugin with Apache License 2.0 6 votes vote down vote up
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 #5
Source File: DockerClientSpotify.java    From doclipser with Eclipse Public License 1.0 6 votes vote down vote up
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 #6
Source File: PushPullIT.java    From docker-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testPushHubPublicImageWithAuth() throws Exception {
  // Push an image to a public repo on Docker Hub and check it succeeds
  final String dockerDirectory = Resources.getResource("dockerDirectory").getPath();
  final RegistryAuth registryAuth = RegistryAuth.builder()
      .username(HUB_AUTH_USERNAME)
      .password(HUB_AUTH_PASSWORD)
      .build();
  final DockerClient client = DefaultDockerClient
      .fromEnv()
      .registryAuthSupplier(new FixedRegistryAuthSupplier(
          registryAuth, RegistryConfigs.create(singletonMap(HUB_NAME, registryAuth))))
      .build();

  client.build(Paths.get(dockerDirectory), HUB_PUBLIC_IMAGE);
  client.push(HUB_PUBLIC_IMAGE);
}
 
Example #7
Source File: PushPullIT.java    From docker-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testPushHubPrivateImageWithAuth() throws Exception {
  // Push an image to a private repo on Docker Hub and check it succeeds
  final String dockerDirectory = Resources.getResource("dockerDirectory").getPath();
  final RegistryAuth registryAuth = RegistryAuth.builder()
      .username(HUB_AUTH_USERNAME)
      .password(HUB_AUTH_PASSWORD)
      .build();
  final DockerClient client = DefaultDockerClient
      .fromEnv()
      .registryAuthSupplier(new FixedRegistryAuthSupplier(
          registryAuth, RegistryConfigs.create(singletonMap(HUB_NAME, registryAuth))))
      .build();

  client.build(Paths.get(dockerDirectory), HUB_PRIVATE_IMAGE);
  client.push(HUB_PRIVATE_IMAGE);
}
 
Example #8
Source File: AbstractDockerMojo.java    From docker-maven-plugin with Apache License 2.0 6 votes vote down vote up
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 #9
Source File: PushPullIT.java    From docker-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testPushHubPublicImageWithAuthFromConfig() throws Exception {
  // Push an image to a public repo on Docker Hub and check it succeeds
  final String dockerDirectory = Resources.getResource("dockerDirectory").getPath();
  final DockerClient client = DefaultDockerClient
      .fromEnv()
      .registryAuthSupplier(new ConfigFileRegistryAuthSupplier(
          new DockerConfigReader(),
          Paths.get(Resources.getResource("dockerConfig/dxia4Config.json").toURI())))
      .build();

  client.build(Paths.get(dockerDirectory), HUB_PUBLIC_IMAGE);
  client.push(HUB_PUBLIC_IMAGE);
}
 
Example #10
Source File: PushPullIT.java    From docker-client with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  final RegistryAuth registryAuth = RegistryAuth.builder()
      .username(LOCAL_AUTH_USERNAME)
      .password(LOCAL_AUTH_PASSWORD)
      .build();
  client = DefaultDockerClient
      .fromEnv()
      .registryAuthSupplier(new FixedRegistryAuthSupplier(
          registryAuth, RegistryConfigs.create(singletonMap(HUB_NAME, registryAuth))))
      .build();

  System.out.printf("- %s\n", testName.getMethodName());
}
 
Example #11
Source File: DockerClientFactory.java    From docker-registry-artifact-plugin with Apache License 2.0 5 votes vote down vote up
private static DefaultDockerClient createClient(ArtifactStoreConfig artifactStoreConfig) throws DockerCertificateException, DockerException, InterruptedException {
    final RegistryAuthSupplierChain registryAuthSupplier = new RegistryAuthSupplierChain(artifactStoreConfig, new AWSTokenRequestGenerator());
    DefaultDockerClient docker = DefaultDockerClient.fromEnv().registryAuthSupplier(registryAuthSupplier).build();

    LOG.info(format("Using docker registry server `{0}`.", artifactStoreConfig.getRegistryUrl()));

    final String result = docker.ping();
    if (!result.equalsIgnoreCase("OK")) {
        throw new RuntimeException("Could not ping the docker server.");
    }
    return docker;
}
 
Example #12
Source File: Docker.java    From james-project with Apache License 2.0 5 votes vote down vote up
public Docker(String imageName)  {
    containerConfig = ContainerConfig.builder()
            .image(imageName)
            .networkDisabled(false)
            .exposedPorts(ImmutableSet.of(EXPOSED_IMAP_PORT))
            .hostConfig(ALL_PORTS_HOST_CONFIG)
            .build();
    
    try {
        dockerClient = DefaultDockerClient.fromEnv().build();
        dockerClient.pull(imageName);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #13
Source File: RedisDockerRule.java    From pay-publicapi with MIT License 5 votes vote down vote up
private void startRedisIfNecessary() throws DockerException {
    try {
        if (container == null) {
            DockerClient docker = DefaultDockerClient.fromEnv().build();
            container = new RedisContainer(docker, host);
        }
    } catch (DockerCertificateException | InterruptedException e) {
        throw new RuntimeException(e);
    }
}
 
Example #14
Source File: DockerContainerConfig.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
public static DefaultDockerClient.Builder defaultDockerClientBuilder() {
  DefaultDockerClient.Builder defaultClient = null;

  try {
    defaultClient = DefaultDockerClient.fromEnv();
  }
  catch (DockerCertificateException e) {
    throw new RuntimeException(e);
  }

  return defaultClient;
}
 
Example #15
Source File: PushPullIT.java    From docker-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testBuildHubPrivateImageWithAuth() throws Exception {
  final String dockerDirectory = Resources.getResource("dockerDirectoryNeedsAuth").getPath();
  final RegistryAuth registryAuth = RegistryAuth.builder()
      .username(HUB_AUTH_USERNAME2)
      .password(HUB_AUTH_PASSWORD2)
      .build();
  final DockerClient client = DefaultDockerClient
      .fromEnv()
      .registryAuthSupplier(new FixedRegistryAuthSupplier(
          registryAuth, RegistryConfigs.create(singletonMap(HUB_NAME, registryAuth))))
      .build();

  client.build(Paths.get(dockerDirectory), "testauth", BuildParam.pullNewerImage());
}
 
Example #16
Source File: DockerClientFactory.java    From docker-elastic-agents-plugin with Apache License 2.0 5 votes vote down vote up
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 #17
Source File: SingularityExecutorModule.java    From Singularity with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
public DockerClient providesDockerClient(
  SingularityExecutorConfiguration configuration
) {
  Builder dockerClientBuilder = DefaultDockerClient
    .builder()
    .uri(URI.create("unix://localhost/var/run/docker.sock"))
    .connectionPoolSize(configuration.getDockerClientConnectionPoolSize());

  if (configuration.getDockerAuthConfig().isPresent()) {
    SingularityExecutorDockerAuthConfig authConfig = configuration
      .getDockerAuthConfig()
      .get();

    if (authConfig.isFromDockerConfig()) {
      try {
        dockerClientBuilder.registryAuth(RegistryAuth.fromDockerConfig().build());
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    } else {
      dockerClientBuilder.registryAuth(
        RegistryAuth
          .builder()
          .email(authConfig.getEmail())
          .username(authConfig.getUsername())
          .password(authConfig.getPassword())
          .serverAddress(authConfig.getServerAddress())
          .build()
      );
    }
  }

  return dockerClientBuilder.build();
}
 
Example #18
Source File: AbstractDockerMojo.java    From dockerfile-maven with Apache License 2.0 5 votes vote down vote up
@Nonnull
private DockerClient openDockerClient() throws MojoExecutionException {
  final RegistryAuthSupplier authSupplier = createRegistryAuthSupplier();

  try {
    return DefaultDockerClient.fromEnv()
        .readTimeoutMillis(readTimeoutMillis)
        .connectTimeoutMillis(connectTimeoutMillis)
        .registryAuthSupplier(authSupplier)
        .useProxy(useProxy)
        .build();
  } catch (DockerCertificateException e) {
    throw new MojoExecutionException("Could not load Docker certificates", e);
  }
}
 
Example #19
Source File: DockerClientBuilder.java    From docker-image-builder with Apache License 2.0 5 votes vote down vote up
DockerClient build(Registry registry, String dockerHost, long connectTimeout, long readTimeout) {
    final DockerClient dockerClient = DefaultDockerClient.builder()
            .authConfig(registry.toAuthConfig())
            .uri(dockerHost)
            .connectTimeoutMillis(connectTimeout)
            .readTimeoutMillis(readTimeout)
            .build();
    return dockerClient;
}
 
Example #20
Source File: DockerRemoteHandler.java    From docker-image-builder with Apache License 2.0 5 votes vote down vote up
public DockerClient buildDockerClient(Registry registry, String dockerHostUri, long connectTimeout, long readTimeout) {

        final DockerClient dockerClient = DefaultDockerClient.builder()
                .authConfig(registry.toAuthConfig())
                .uri(dockerHostUri)
                .connectTimeoutMillis(connectTimeout)
                .readTimeoutMillis(readTimeout)
                .build();
        return dockerClient;
    }
 
Example #21
Source File: DockerService.java    From selenium-jupiter with Apache License 2.0 5 votes vote down vote up
public void updateDockerClient(String url) {
    if (localDaemon) {
        log.debug("Updating Docker client using URL {}", url);
        dockerClient = DefaultDockerClient.builder().uri(url).build();
        localDaemon = false;
    }
}
 
Example #22
Source File: DockerHelper.java    From repairnator with MIT License 5 votes vote down vote up
public static DockerClient initDockerClient() {
    DockerClient docker;
    try {
        docker = DefaultDockerClient.fromEnv().build();
    } catch (DockerCertificateException e) {
        throw new RuntimeException("Error while initializing docker client.");
    }
    return docker;
}
 
Example #23
Source File: DockerConfig.java    From paas with Apache License 2.0 5 votes vote down vote up
@Bean(name = "dockerClient")
    DockerClient dockerClient() {
        return DefaultDockerClient.builder()
                .uri(URI.create(serverUrl))
//                        .dockerCertificates(new DockerCertificates(Paths.get("D:/")))
                .build();
    }
 
Example #24
Source File: DockerSwarmConfig.java    From paas with Apache License 2.0 5 votes vote down vote up
@Bean(name = "dockerSwarmClient")
    DockerClient dockerClient() {
        return DefaultDockerClient.builder()
                .uri(URI.create(serverUrl))
//                        .dockerCertificates(new DockerCertificates(Paths.get("D:/")))
                .build();
    }
 
Example #25
Source File: PushPullIT.java    From docker-client with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void before() throws Exception {
  // Pull the registry image down once before any test methods in this class run
  DefaultDockerClient.fromEnv().build().pull(REGISTRY_IMAGE);
}
 
Example #26
Source File: GCloudEmulatorManager.java    From flink with Apache License 2.0 4 votes vote down vote up
public static void launchDocker() throws DockerException, InterruptedException, DockerCertificateException {
	// Create a client based on DOCKER_HOST and DOCKER_CERT_PATH env vars
	docker = DefaultDockerClient.fromEnv().build();

	terminateAndDiscardAnyExistingContainers(true);

	LOG.info("");
	LOG.info("/===========================================");
	LOG.info("| GCloud Emulator");

	ContainerInfo containerInfo;
	String id;

	try {
		docker.inspectImage(DOCKER_IMAGE_NAME);
	} catch (ImageNotFoundException e) {
		// No such image so we must download it first.
		LOG.info("| - Getting docker image \"{}\"", DOCKER_IMAGE_NAME);
		docker.pull(DOCKER_IMAGE_NAME, message -> {
			if (message.id() != null && message.progress() != null) {
				LOG.info("| - Downloading > {} : {}", message.id(), message.progress());
			}
		});
	}

	// No such container. Good, we create one!
	LOG.info("| - Creating new container");

	// Bind container ports to host ports
	final Map<String, List<PortBinding>> portBindings = new HashMap<>();
	portBindings.put(INTERNAL_PUBSUB_PORT, Collections.singletonList(PortBinding.randomPort("0.0.0.0")));

	final HostConfig hostConfig = HostConfig.builder().portBindings(portBindings).build();

	// Create new container with exposed ports
	final ContainerConfig containerConfig = ContainerConfig.builder()
		.hostConfig(hostConfig)
		.exposedPorts(INTERNAL_PUBSUB_PORT)
		.image(DOCKER_IMAGE_NAME)
		.cmd("sh", "-c", "mkdir -p /opt/data/pubsub ; gcloud beta emulators pubsub start --data-dir=/opt/data/pubsub  --host-port=0.0.0.0:" + INTERNAL_PUBSUB_PORT)
		.build();

	final ContainerCreation creation = docker.createContainer(containerConfig, CONTAINER_NAME_JUNIT);
	id = creation.id();

	containerInfo = docker.inspectContainer(id);

	if (!containerInfo.state().running()) {
		LOG.warn("| - Starting it up ....");
		docker.startContainer(id);
		Thread.sleep(1000);
	}

	containerInfo = docker.inspectContainer(id);

	dockerIpAddress = "127.0.0.1";

	Map<String, List<PortBinding>> ports = containerInfo.networkSettings().ports();

	assertNotNull("Unable to retrieve the ports where to connect to the emulators", ports);
	assertEquals("We expect 1 port to be mapped", 1, ports.size());

	pubsubPort = getPort(ports, INTERNAL_PUBSUB_PORT, "PubSub");

	LOG.info("| Waiting for the emulators to be running");

	// PubSub exposes an "Ok" at the root url when running.
	if (!waitForOkStatus("PubSub", pubsubPort)) {
		// Oops, we did not get an "Ok" within 10 seconds
		startHasFailedKillEverything();
	}
	LOG.info("\\===========================================");
	LOG.info("");
}
 
Example #27
Source File: DockerClientFactory.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * This method returns the DockerClient dependent on the current OS.
 * 
 * @return
 * @throws DockerCertificateException
 * @throws IOException
 * @throws InterruptedException
 */
public DockerClient getDockerClient() throws DockerCertificateException, IOException, InterruptedException {
	DockerClient client = null;

	// If this is not Linux, then we have to find DOCKER_HOST
	if (!Platform.getOS().equals(Platform.OS_LINUX)) {

		// See if we can get the DOCKER_HOST environment variaable
		String dockerHost = System.getenv("DOCKER_HOST");
		if (dockerHost == null) {

			// If not, run a script to see if we can get it
			File script = getDockerConnectionScript();
			String[] scriptExec = null;
			if (Platform.getOS().equals(Platform.OS_MACOSX)) {
				scriptExec = new String[] { script.getAbsolutePath() };
			} else if (Platform.getOS().equals(Platform.OS_WIN32)) {
				scriptExec = new String[] { "cmd.exe", "/C", script.getAbsolutePath() };
			}

			// Execute the script to get the DOCKER vars.
			Process process = new ProcessBuilder(scriptExec).start();
			process.waitFor();
			int exitValue = process.exitValue();
			if (exitValue == 0) {

				// Read them into a Properties object
				InputStream processInputStream = process.getInputStream();
				Properties dockerSettings = new Properties();
				// Properties.load screws up windows path separators
				// so if windows, just get the string from the stream
				if (Platform.getOS().equals(Platform.OS_WIN32)) {
					String result = streamToString(processInputStream).trim();
					String[] dockerEnvs = result.split(System.lineSeparator());
					for (String s : dockerEnvs) {
						String[] env = s.split("=");
						dockerSettings.put(env[0], env[1]);
					}
				} else {
					dockerSettings.load(processInputStream);
				}
				
				// Create the Builder object that wil build the DockerClient
				Builder builder = new Builder();

				// Get the DOCKER_HOST and CERT_PATH vars
				String endpoint = dockerSettings.getProperty("DOCKER_HOST");
				Path dockerCertPath = Paths.get(dockerSettings.getProperty("DOCKER_CERT_PATH"));

				System.out.println("DOCKERHOST: " + endpoint);
				System.out.println("DOCKER CERT PATH: " + dockerSettings.getProperty("DOCKER_CERT_PATH"));
				// Set up the certificates
				DockerCertificates certs = DockerCertificates.builder().dockerCertPath(dockerCertPath).build();

				// Set the data need for the builder.
				String stripped = endpoint.replaceAll(".*://", "");
				HostAndPort hostAndPort = HostAndPort.fromString(stripped);
				String hostText = hostAndPort.getHostText();
				String scheme = certs != null ? "https" : "http";
				int port = hostAndPort.getPortOrDefault(2375);
				String address = hostText;
				builder.uri(scheme + "://" + address + ":" + port);
				if (certs != null) {
					builder.dockerCertificates(certs);
				}

				// Build the Dockerclient!
				client = builder.build();

			} else {
				// log what happened if the process did not end as expected
				// an exit value of 1 should indicate no connection found
				InputStream processErrorStream = process.getErrorStream();
				String errorMessage = streamToString(processErrorStream);
				logger.error("Error in getting DOCKER variables: " + errorMessage);
			}
		} else {
			client = DefaultDockerClient.fromEnv().build();
		}
	} else {
		// It was equal to Linux, so just use the default stuff.
		client = DefaultDockerClient.fromEnv().build();
	}

	return client;
}
 
Example #28
Source File: AbstractDockerMojoTest.java    From docker-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
protected DefaultDockerClient.Builder getBuilder() throws DockerCertificateException {
  return builder;
}
 
Example #29
Source File: DockerHelper.java    From paas with Apache License 2.0 4 votes vote down vote up
public static void execute(String ip, String port, DockerAction dockerAction) throws Exception {
    DockerClient docker = DefaultDockerClient.builder().uri(protocol.concat(ip).concat(":" + port)).apiVersion(apiVersion).build();
    dockerAction.action(docker);
    docker.close();
}
 
Example #30
Source File: AbstractDockerMojo.java    From docker-maven-plugin with Apache License 2.0 4 votes vote down vote up
protected DefaultDockerClient.Builder getBuilder() throws DockerCertificateException {
  return DefaultDockerClient.fromEnv()
    .readTimeoutMillis(0);
}