Refine search
public EnvironmentAndSystemPropertyClientProviderStrategy() { // Try using environment variables config = DefaultDockerClientConfig.createDefaultConfigBuilder().build(); }
/** * This will set all fields in the builder to those contained in the Properties object. The Properties object should contain the * following docker-java configuration keys: DOCKER_HOST, DOCKER_TLS_VERIFY, api.version, registry.username, registry.password, * registry.email, DOCKER_CERT_PATH, and DOCKER_CONFIG. */ public Builder withProperties(Properties p) { return withDockerHost(p.getProperty(DOCKER_HOST)) .withDockerTlsVerify(p.getProperty(DOCKER_TLS_VERIFY)) .withDockerConfig(p.getProperty(DOCKER_CONFIG)) .withDockerCertPath(p.getProperty(DOCKER_CERT_PATH)) .withApiVersion(p.getProperty(API_VERSION)) .withRegistryUsername(p.getProperty(REGISTRY_USERNAME)) .withRegistryPassword(p.getProperty(REGISTRY_PASSWORD)) .withRegistryEmail(p.getProperty(REGISTRY_EMAIL)) .withRegistryUrl(p.getProperty(REGISTRY_URL)); }
/** * Allows you to build the config without system environment interfering for more robust testing */ static Builder createDefaultConfigBuilder(Map<String, String> env, Properties systemProperties) { Properties properties = loadIncludedDockerProperties(systemProperties); properties = overrideDockerPropertiesWithSettingsFromUserHome(properties, systemProperties); properties = overrideDockerPropertiesWithEnv(properties, env); properties = overrideDockerPropertiesWithSystemProperties(properties, systemProperties); return new Builder().withProperties(properties); }
return new Container(containerResponse, getMappedPorts(ports), getHost(clientConfig.getDockerHost()), client);
public static DockerClientBuilder getInstance(Builder dockerClientConfigBuilder) { return getInstance(dockerClientConfigBuilder.build()); }
public static DockerClient buildDockerClient(Map<String, String> providerProperties) { Properties properties = new Properties(); properties.put(DefaultDockerClientConfig.API_VERSION, "1.22"); properties.putAll(providerProperties); DockerClientConfig config = new DefaultDockerClientConfig.Builder().withProperties(properties).build(); NettyDockerCmdExecFactory execFactory = new NettyDockerCmdExecFactory(); return DockerClientBuilder.getInstance(config).withDockerCmdExecFactory(execFactory).build(); }
public static DockerClient build() { if (dockerClient == null) { DefaultDockerClientConfig.Builder builder = new DefaultDockerClientConfig.Builder(); builder = builder.withApiVersion("1.12"); String dockerHostEnv = System.getenv("DOCKER_HOST"); if (StringUtils.isBlank(dockerHostEnv)) { builder.withDockerHost("unix:///var/run/docker.sock"); } DockerClientConfig config = builder.build(); dockerClient = DockerClientBuilder.getInstance(config).build(); } return dockerClient; }
@Override public DockerScanner build() { if (dockerClient==null) { DefaultDockerClientConfig cc = configBuilder.build(); this.dockerClient = DockerClientBuilder.getInstance(cc).build(); } return new DockerScanner(this); }
private static DockerClient createDockerClient(DockerConfig config) { JerseyDockerCmdExecFactory dockerFactory = new JerseyDockerCmdExecFactory() .withMaxPerRouteConnections(config.maxPerRouteConnections()) .withMaxTotalConnections(config.maxTotalConnections()) .withConnectTimeout(config.connectTimeoutMillis()) .withReadTimeout(config.readTimeoutMillis()); DockerClientConfig dockerClientConfig = new DefaultDockerClientConfig.Builder() .withDockerHost(config.uri()) .build(); return DockerClientImpl.getInstance(dockerClientConfig) .withDockerCmdExecFactory(dockerFactory); } }
public DockerScannerBuilder withLocalDockerDaemon() { configBuilder.withDockerHost(LOCAL_DOCKER_DAEMON); return this; }
/** * This will set all fields in the builder to those contained in the Properties object. The Properties object should contain the * following docker-java configuration keys: DOCKER_HOST, DOCKER_TLS_VERIFY, api.version, registry.username, registry.password, * registry.email, DOCKER_CERT_PATH, and DOCKER_CONFIG. */ public Builder withProperties(Properties p) { return withDockerHost(p.getProperty(DOCKER_HOST)) .withDockerTlsVerify(p.getProperty(DOCKER_TLS_VERIFY)) .withDockerConfig(p.getProperty(DOCKER_CONFIG)) .withDockerCertPath(p.getProperty(DOCKER_CERT_PATH)) .withApiVersion(p.getProperty(API_VERSION)) .withRegistryUsername(p.getProperty(REGISTRY_USERNAME)) .withRegistryPassword(p.getProperty(REGISTRY_PASSWORD)) .withRegistryEmail(p.getProperty(REGISTRY_EMAIL)) .withRegistryUrl(p.getProperty(REGISTRY_URL)); }
public static DockerClientBuilder getInstance(Builder dockerClientConfigBuilder) { return getInstance(dockerClientConfigBuilder.build()); }
/** Creates a new {@link DockerClient} */ private static SharableDockerClient makeClient(final String dockerUri, final String credentialsId, final Integer readTimeoutInMillisecondsOrNull, final Integer connectTimeoutInMillisecondsOrNull) { final DockerClient actualClient = DockerClientBuilder.getInstance( new DefaultDockerClientConfig.Builder() .withDockerHost(dockerUri) .withCustomSslConfig(toSSlConfig(credentialsId)) ) .withDockerCmdExecFactory(new NettyDockerCmdExecFactory() .withReadTimeout(readTimeoutInMillisecondsOrNull) .withConnectTimeout(connectTimeoutInMillisecondsOrNull)) .build(); final SharableDockerClient multiUsageClient = new SharableDockerClient(actualClient); return multiUsageClient; }
private static DockerClient createDockerClient(String dockerUrl, String dockerVersion, String dockerCertPath, AuthConfig authConfig) { // TODO JENKINS-26512 SSLConfig dummySSLConf = (new SSLConfig() { public SSLContext getSSLContext() throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException { return null; } }); if (dockerCertPath != null) { dummySSLConf = new LocalDirectorySSLConfig(dockerCertPath); } DefaultDockerClientConfig.Builder configBuilder = new DefaultDockerClientConfig.Builder().withDockerHost(dockerUrl) .withApiVersion(dockerVersion).withCustomSslConfig(dummySSLConf); if (authConfig != null) { configBuilder.withRegistryUsername(authConfig.getUsername()) .withRegistryEmail(authConfig.getEmail()) .withRegistryPassword(authConfig.getPassword()) .withRegistryUrl(authConfig.getRegistryAddress()); } // using jaxrs/jersey implementation here (netty impl is also available) DockerCmdExecFactory dockerCmdExecFactory = new DockerCmdExecFactoryImpl() .withConnectTimeout(1000) .withMaxTotalConnections(1) .withMaxPerRouteConnections(1); return DockerClientBuilder.getInstance(configBuilder).withDockerCmdExecFactory(dockerCmdExecFactory).build(); }
private DockerClientImpl() { this(DefaultDockerClientConfig.createDefaultConfigBuilder().build()); }
/** * Allows you to build the config without system environment interfering for more robust testing */ static Builder createDefaultConfigBuilder(Map<String, String> env, Properties systemProperties) { Properties properties = loadIncludedDockerProperties(systemProperties); properties = overrideDockerPropertiesWithSettingsFromUserHome(properties, systemProperties); properties = overrideDockerPropertiesWithEnv(properties, env); properties = overrideDockerPropertiesWithSystemProperties(properties, systemProperties); return new Builder().withProperties(properties); }
@NotNull private DockerClientConfig tryConfiguration() { URI dockerHost = URI.create(SOCKET_LOCATION); config = new DelegatingDockerClientConfig( DefaultDockerClientConfig.createDefaultConfigBuilder() .withDockerHost("tcp://localhost:0") .withDockerTlsVerify(false) .build() ) { @Override public URI getDockerHost() { return dockerHost; } }; client = getClientForConfig(config); final int timeout = Integer.parseInt(System.getProperty(PING_TIMEOUT_PROPERTY_NAME, PING_TIMEOUT_DEFAULT)); ping(client, timeout); return config; }
@NotNull protected DockerClientConfig tryConfiguration(String dockerHost) { config = DefaultDockerClientConfig.createDefaultConfigBuilder() .withDockerHost(dockerHost) .withDockerTlsVerify(false) .build(); client = getClientForConfig(config); final int timeout = Integer.getInteger(PING_TIMEOUT_PROPERTY_NAME, PING_TIMEOUT_DEFAULT); ping(client, timeout); return config; } }
@Override public void test() throws InvalidConfigurationException { try { boolean installed = DockerMachineClient.instance().isInstalled(); checkArgument(installed, "docker-machine executable was not found on PATH (" + Arrays.toString(CommandLine.getSystemPath()) + ")"); Optional<String> machineNameOptional = DockerMachineClient.instance().getDefaultMachine(); checkArgument(machineNameOptional.isPresent(), "docker-machine is installed but no default machine could be found"); String machineName = machineNameOptional.get(); log.info("Found docker-machine, and will use machine named {}", machineName); DockerMachineClient.instance().ensureMachineRunning(machineName); String dockerDaemonIpAddress = DockerMachineClient.instance().getDockerDaemonIpAddress(machineName); log.info("Docker daemon IP address for docker machine {} is {}", machineName, dockerDaemonIpAddress); config = DefaultDockerClientConfig.createDefaultConfigBuilder() .withDockerHost("tcp://" + dockerDaemonIpAddress + ":2376") .withDockerTlsVerify(true) .withDockerCertPath(Paths.get(System.getProperty("user.home") + "/.docker/machine/certs/").toString()) .build(); client = getClientForConfig(config); } catch (Exception e) { throw new InvalidConfigurationException(e.getMessage()); } // If the docker-machine VM has started, the docker daemon may still not be ready. Retry pinging until it works. final int timeout = Integer.parseInt(System.getProperty(PING_TIMEOUT_PROPERTY_NAME, PING_TIMEOUT_DEFAULT)); ping(client, timeout); }
@NotNull protected DockerClientConfig tryConfiguration(String dockerHost) { Path dockerSocketFile = Paths.get(DOCKER_SOCK_PATH); Integer mode; try { mode = (Integer) Files.getAttribute(dockerSocketFile, "unix:mode"); } catch (IOException e) { throw new InvalidConfigurationException("Could not find unix domain socket", e); } if ((mode & 0xc000) != SOCKET_FILE_MODE_MASK) { throw new InvalidConfigurationException("Found docker unix domain socket but file mode was not as expected (expected: srwxr-xr-x). This problem is possibly due to occurrence of this issue in the past: https://github.com/docker/docker/issues/13121"); } config = DefaultDockerClientConfig.createDefaultConfigBuilder() .withDockerHost(dockerHost) .withDockerTlsVerify(false) .build(); client = getClientForConfig(config); final int timeout = Integer.parseInt(System.getProperty(PING_TIMEOUT_PROPERTY_NAME, PING_TIMEOUT_DEFAULT)); ping(client, timeout); return config; }