Exemplo n.º 1
0
 /**
  * @return A Builder with its Docker Client configured automatically using the <code>DOCKER_HOST
  *     </code> and <code>DOCKER_CERT_PATH</code> environment variables, or sensible defaults if
  *     they are absent.
  */
 public static Builder fromEnv() {
   try {
     DefaultDockerClient.fromEnv().uri();
     return builder().dockerClient(DefaultDockerClient.fromEnv().build());
   } catch (DockerCertificateException e) {
     throw new RuntimeException("unable to create Docker client from environment", e);
   }
 }
  public static DockerClient buildDockerClient(String dockerEndPointUrl)
      throws CarbonKernelHandlerException {
    /*
    implements the singleton design pattern on the DockerClient instance
     */
    try {
      if (DOCKER_CLIENT == null) {
        if (dockerEndPointUrl == null) {
          DOCKER_CLIENT = DefaultDockerClient.fromEnv().build();
        } else {
          DOCKER_CLIENT = DefaultDockerClient.builder().uri(dockerEndPointUrl).build();
        }
      }
    } catch (DockerCertificateException exception) {
      String message = "Could not create the Docker Client instance.";
      LOG.error(message, exception);
      throw new CarbonKernelHandlerException(message, exception);
    }

    return DOCKER_CLIENT;
  }