@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); } }
DockerHost.defaultCertPath())); final Builder builder = new Builder(); builder.uri(endpoint); } else if (endpoint.startsWith(NPIPE_SCHEME + "://")) { builder.uri(endpoint); } else { final String stripped = endpoint.replaceAll(".*://", ""); final String address = isNullOrEmpty(hostText) ? DockerHost.defaultAddress() : hostText; builder.uri(scheme + "://" + address + ":" + port); builder.dockerCertificates(certs.get());
dockerBuilder.dockerCertificates(new SkipVerifyDockerCertificatesStore()); dockerBuilder.uri(this.swarmMgrUri); docker = dockerBuilder.build();
this.docker = DefaultDockerClient.fromEnv().build();
try { if (System.getProperty("os.name").toLowerCase().contains("mac")) { dockerClient = DefaultDockerClient.builder().uri(DefaultDockerClient.DEFAULT_UNIX_ENDPOINT).build(); dockerClient = DefaultDockerClient.fromEnv().build(); Info info = dockerClient.info(); LOG.info("Connected to Docker Client Info: " + info); dockerClient = DefaultDockerClient.fromEnv().build(); Info info = dockerClient.info(); LOG.info("Connected to Docker Client Info: " + info);
try { if (System.getProperty("os.name").toLowerCase().contains("mac")) { dockerClient = DefaultDockerClient.builder().uri(DefaultDockerClient.DEFAULT_UNIX_ENDPOINT).build(); dockerClient = DefaultDockerClient.fromEnv().build(); Info info = dockerClient.info(); LOG.info("Connected to Docker Client Info: " + info); dockerClient = DefaultDockerClient.fromEnv().build(); Info info = dockerClient.info(); LOG.info("Connected to Docker Client Info: " + info);
/** * 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; }
@Override public DefaultDockerClient.Builder configure(TestContext testContext, VirtualResource virtualResource, PropertiesReader configReader) { try { DefaultDockerClient.Builder builder = DefaultDockerClient.fromEnv(); PropertiesReader reader = configReader; if (reader.isEmpty()) { reader = testContext.getPropertiesReader(DEFAULT_CONFIG_KEY); } if (!reader.isEmpty()) { RegistryAuth registryAuth = RegistryAuth.builder() .serverAddress(reader.getProperty("uri")) .email(reader.getProperty("email")) .username(reader.getProperty("username")) .password(reader.getProperty("password")) .build(); RegistryAuthSupplier dockerHubAuthSupplier = new DockerHubRegistryAuthSupplier(registryAuth); //TODO: explore making these configuration configurable via .testify.yml file builder.registryAuthSupplier(dockerHubAuthSupplier) .connectTimeoutMillis(10000) .connectionPoolSize(16); } return builder; } catch (DockerCertificateException e) { throw ExceptionUtil.INSTANCE.propagate(e); } }
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(); }
public static void main(String[] args) throws DockerException, InterruptedException { System.out.println("Testing"); // Create a client based on DOCKER_HOST and DOCKER_CERT_PATH env vars try { final DockerClient docker = DefaultDockerClient.builder() .uri("http://192.168.99.100:2375") .build(); //Create a container ContainerConfig cc = ContainerConfig.builder() .image("nginx") .build(); final ContainerCreation container = docker.createContainer(cc); docker.startContainer(container.id()); } catch (Exception ex) { ex.printStackTrace(); } } }
@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; }
public static DockerClient buildClient(URI dockerHost, Path certificatesPath) { try { if (dockerHost == null) { logger.info("Configuring docker host from environment"); return DefaultDockerClient.fromEnv().build(); } else { logger.info("Configuring docker host from configuration"); DefaultDockerClient.Builder builder = DefaultDockerClient.builder().uri(dockerHost); if (certificatesPath != null) { builder.dockerCertificates(new DockerCertificates(certificatesPath)); } return builder.build(); } } catch (DockerCertificateException e) { logger.error("Could not read certificates", e); throw new IllegalArgumentException("Could not read certificates: " + e.getMessage()); } }
/** * Public constructor. * * @param path {@code Path} of the file to write * @param append whether to append to the file or overwrite * @param targetImageName the {@code Pattern} for matching the name of the Docker image being profiled * @param dockerDaemonAddress the address of the Docker daemon */ public DockerJsonBenchmarkConsumer( final Path path, final boolean append, final Pattern targetImageName, final String dockerDaemonAddress) { super(path, append); _targetImageName = targetImageName; _dockerClient = DefaultDockerClient.builder() .uri(dockerDaemonAddress) .build(); }
DockerRule(DockerRuleBuilder builder) { this.builder = builder; this.imageNameWithTag = imageNameWithTag(builder.imageName()); try { dockerClient = DefaultDockerClient.fromEnv().build(); log.debug("server.info: {}", dockerClient.info()); log.debug("server.version: {}", dockerClient.version()); if (builder.imageAlwaysPull() || ! imageAvaliable(dockerClient, imageNameWithTag)) { dockerClient.pull(imageNameWithTag); } } catch (ImageNotFoundException e) { throw new ImagePullException(String.format("Image '%s' not found", imageNameWithTag), e); } catch (DockerCertificateException | DockerException | InterruptedException e) { throw new IllegalStateException(e); } }
@Override public Statement apply(Statement statement, Description description) { try { DefaultDockerClient client = DefaultDockerClient.fromEnv() .connectTimeoutMillis(5000L) .readTimeoutMillis(20000L) .registryAuthSupplier(new FixedRegistryAuthSupplier()) .build(); client.ping(); client.pull(IMAGE); client.close(); } catch (Throwable t) { Assume.assumeNoException(t); } return wrappedRule.apply(statement, description); }
public DefaultDockerClient build() { if (dockerAuth && registryAuthSupplier == null && registryAuth == null) { try { registryAuth(RegistryAuth.fromDockerConfig().build()); } catch (IOException e) { log.warn("Unable to use Docker auth info", e); } } // read the docker config file for auth info if nothing else was specified if (registryAuthSupplier == null) { registryAuthSupplier(new ConfigFileRegistryAuthSupplier()); } return new DefaultDockerClient(this); } }
private DockerInstance(String imageName, String[] commands, String containerName, HostConfig hostConfig, String[] env, ImageStrategy imageStrategy, String[] usedContainerPorts) { this.imageName = imageName; this.commands = commands; this.containerName = containerName; this.hostConfig = hostConfig; this.env = env; this.usedContainerPorts = usedContainerPorts; try { dockerClient = DefaultDockerClient.fromEnv().build(); } catch (DockerCertificateException e) { throw new RuntimeException(e); } this.imageStrategy = imageStrategy; }