/** * 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)); }
@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; }
@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 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; }
private static DockerClientConfig configWithServerUrl(String serverUrl) { return DefaultDockerClientConfig.createDefaultConfigBuilder().withDockerHost(serverUrl).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; }
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); } }
private static DockerClient getDockerClient(String host) { NettyDockerCmdExecFactory nettyDockerCmdExecFactory; nettyDockerCmdExecFactory = new NettyDockerCmdExecFactory(); if (StringUtils.isEmpty(host)) { return DockerClientBuilder.getInstance().withDockerCmdExecFactory(nettyDockerCmdExecFactory).build(); } DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder() .withDockerHost(host) .build(); return DockerClientBuilder.getInstance(config).withDockerCmdExecFactory(nettyDockerCmdExecFactory).build(); }
public DockerClient getDefaultDockerClient(String defaultPath) { final DefaultDockerClientConfig.Builder configBuilder = DefaultDockerClientConfig .createDefaultConfigBuilder(); configBuilder.withDockerHost(defaultPath); return DockerClientBuilder.getInstance(configBuilder.build()).build(); } }
public DockerScannerBuilder withLocalDockerDaemon() { configBuilder.withDockerHost(LOCAL_DOCKER_DAEMON); return this; }
public DockerClient getDefaultDockerClient(String defaultPath) { final DefaultDockerClientConfig.Builder configBuilder = DefaultDockerClientConfig .createDefaultConfigBuilder(); configBuilder.withDockerHost(defaultPath); return DockerClientBuilder.getInstance(configBuilder.build()).build(); } }
@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; } }
@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; }
private static DockerClientConfig configWithServerUrl(String serverUrl) { return DefaultDockerClientConfig.createDefaultConfigBuilder().withDockerHost(serverUrl).build(); }
@Test @Ignore public void getDockerHostIpAddressShouldReturnNullWhenUnsupportedUriScheme() { DockerClientConfig configuration = DefaultDockerClientConfig.createDefaultConfigBuilder().withDockerHost("gopher://12.23.34.45").build(); String actual = DockerClientConfigUtils.getDockerHostIpAddress(configuration); assertNull(actual); } }
@Test public void getDockerHostIpAddressShouldReturnLocalhostWhenUnixSocket() { DockerClientConfig configuration = DefaultDockerClientConfig.createDefaultConfigBuilder() .withDockerHost("unix:///var/run/docker.sock") .withDockerTlsVerify(false) // TODO - check wrt. https://github.com/docker-java/docker-java/issues/588 .build(); String actual = DockerClientConfigUtils.getDockerHostIpAddress(configuration); assertEquals("localhost", actual); }
@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; } }
@Test @Ignore public void getDockerHostIpAddressShouldReturnDockerHostIpWhenHttpsUri() { DockerClientConfig configuration = DefaultDockerClientConfig.createDefaultConfigBuilder().withDockerHost("https://12.23.34.45").build(); String actual = DockerClientConfigUtils.getDockerHostIpAddress(configuration); assertEquals("12.23.34.45", actual); }
@Test public void getDockerHostIpAddressShouldReturnDockerHostIpWhenTcpUri() { DockerClientConfig configuration = DefaultDockerClientConfig.createDefaultConfigBuilder() .withDockerHost("tcp://12.23.34.45") .withDockerTlsVerify(false) // TODO - check wrt. https://github.com/docker-java/docker-java/issues/588 .build(); String actual = DockerClientConfigUtils.getDockerHostIpAddress(configuration); assertEquals("12.23.34.45", actual); }
@Test @Ignore public void getDockerHostIpAddressShouldReturnDockerHostIpWhenHttpUri() { DockerClientConfig configuration = DefaultDockerClientConfig.createDefaultConfigBuilder().withDockerHost("http://12.23.34.45").build(); String actual = DockerClientConfigUtils.getDockerHostIpAddress(configuration); assertEquals("12.23.34.45", actual); }