@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); } }
@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 Throwables.propagate(e); } } else { dockerClientBuilder.registryAuth(RegistryAuth.builder() .email(authConfig.getEmail()) .username(authConfig.getUsername()) .password(authConfig.getPassword()) .serverAddress(authConfig.getServerAddress()) .build()); } } return dockerClientBuilder.build(); }
LocalDockerRunner(ScheduledExecutorService executorService, StateManager stateManager) { LOG.info("creating a client"); try { client = DefaultDockerClient.fromEnv().build(); } catch (DockerCertificateException e) { throw new RuntimeException(e); } executorService.scheduleAtFixedRate(this::checkStatuses, 1, CHECK_INTERVAL, TimeUnit.SECONDS); this.stateManager = Objects.requireNonNull(stateManager); }
@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 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(); }
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; }
private static DefaultDockerClient givenDockerClient() throws DockerCertificateException { return DefaultDockerClient.fromEnv().build(); }
public Docker() throws DockerCertificateException { this.client = DefaultDockerClient.fromEnv().build(); }
protected static DockerClient createDockerClient(DockerClientConfig config) { final RegistryAuth registryAuth = getRegistryAuth(config); try { if (registryAuth != null) { return DefaultDockerClient.fromEnv().registryAuth(registryAuth).build(); } else { return DefaultDockerClient.fromEnv().build(); } } catch (DockerCertificateException e) { throw new RuntimeException(e); } }
@Before public void setUp() throws Exception { docker = DefaultDockerClient.fromEnv().build(); }
public void updateDockerClient(String url) { log.debug("Updating Docker client using URL {}", url); dockerClient = DefaultDockerClient.builder().uri(url).build(); }
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); } }
protected DockerClient createDockerClient() throws DockerClientException { try { return DefaultDockerClient.fromEnv() // .connectTimeoutMillis(5000) // .readTimeoutMillis(20000) // .build(); } catch (final IllegalStateException | IllegalArgumentException | DockerCertificateException e) { throw new DockerClientException("Unable to create docker client", e); } }
public static DockerClient initDockerClient() { DockerClient docker; try { docker = DefaultDockerClient.fromEnv().build(); } catch (DockerCertificateException e) { throw new RuntimeException("Error while initializing docker client."); } return docker; }
public DockerTaskRunner() throws Exception { this.docker = DefaultDockerClient.fromEnv().build(); this.client = new Docker(this.docker); // Check swarm status // try { // this.swarm = this.docker.inspectSwarm(); // if (this.swarm != null && this.swarm.id() != null) { // this.isSwarm = true; // } // } catch (Exception e) { // // OK, It will show that this node isn't a docker swarm node or manager // } }
@Override protected void init() { String url = settings.get(DOCKER_URL); if (url.startsWith("unix://")) { client = new DefaultDockerClient(url); } else { client = DefaultDockerClient.builder().uri(url).build(); } }
protected DockerClient createDockerClient() { try { return DefaultDockerClient.fromEnv().build(); } catch (DockerCertificateException e) { throw new IllegalStateException("Could not create docker client from environement", e); } }
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; } }
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; } }
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); } }