@Override protected Result check() throws Exception { try { dockerClient.ping(); return Result.healthy(); } catch (final Exception ex) { return Result.unhealthy(ex); } } }
private void connectToDocker() { try { LOG.debug("Connecting to Docker"); dockerClient = DefaultDockerClient.fromEnv().build(); dockerClient.ping(); LOG.debug("Connection to Docker established"); } catch (DockerException | DockerCertificateException | InterruptedException e) { throw new EnvironmentBuilderException("Unable to connect to Docker", e); } }
private DockerClient connectToDocker() { try { LOG.debug("Connecting to Docker"); DockerClient docker = DefaultDockerClient.fromEnv().build(); docker.ping(); LOG.debug("Connection to Docker established"); return docker; } catch (DockerException | DockerCertificateException | InterruptedException e) { throw new EnvironmentBuilderException("Unable to connect to Docker", e); } }
@Override public Map<String, String> validateSettings(Map<String, String> settings) { Map<String, String> errors = new HashMap<>(); String url = settings.get(DOCKER_URL); logger().info("Testing docker container for url {}", url); try { DockerClient testClient; if (url.startsWith("unix://")) { testClient = new DefaultDockerClient(url); } else { testClient = DefaultDockerClient.builder().uri(settings.get(DOCKER_URL)).build(); } testClient.ping(); } catch (DockerException | InterruptedException | NullPointerException e) { errors.put("Connection error", "Impossible to connect to " + settings.get(DOCKER_URL)); } return errors; }