For IntelliJ IDEA and
Android Studio


private <T> T runInsideDocker(DockerClient client, Consumer<CreateContainerCmd> createContainerCmdConsumer, BiFunction<DockerClient, String, T> block) { checkAndPullImage(client, TINY_IMAGE); CreateContainerCmd createContainerCmd = client.createContainerCmd(TINY_IMAGE) .withLabels(DEFAULT_LABELS); createContainerCmdConsumer.accept(createContainerCmd); String id = createContainerCmd.exec().getId(); try { client.startContainerCmd(id).exec(); return block.apply(client, id); } finally { try { client.removeContainerCmd(id).withRemoveVolumes(true).withForce(true).exec(); } catch (NotFoundException | InternalServerErrorException ignored) { log.debug("", ignored); } } }
@Test public void testWithAContainerWithLabels() throws InterruptedException { Map<String, String> labels = new LinkedHashMap<>(); labels.put("service.type", "http-endpoint"); labels.put("ssl", "true"); CreateContainerResponse container = client.createContainerCmd("nginx") .withExposedPorts(ExposedPort.tcp(80), ExposedPort.tcp(443)) .withPortBindings(PortBinding.parse("80")) .withLabels(labels) .exec(); AtomicBoolean done = new AtomicBoolean(); Future<Void> future = Future.future(); future.setHandler(ar -> done.set(ar.succeeded())); bridge.scan(future); await().untilAtomic(done, is(true)); assertThat(bridge.getServices()).hasSize(0); done.set(false); client.startContainerCmd(container.getId()).exec(); Future<Void> future2 = Future.future(); future2.setHandler(ar -> done.set(ar.succeeded())); bridge.scan(future2); await().untilAtomic(done, is(true)); assertThat(bridge.getServices()).hasSize(1); DockerService service = bridge.getServices().get(0); assertThat(service.records()).hasSize(1); assertThat(service.records().get(0).getLocation().getString("endpoint")).startsWith("https"); }
labels = new HashMap<>(labels != null ? labels : Collections.emptyMap()); labels.putAll(DockerClientFactory.DEFAULT_LABELS); createCommand.withLabels(labels);
containerConfig.withLabels(map);
createContainerCmd.withLabels(containerConfiguration.getLabels());
private <T> T runInsideDocker(DockerClient client, Consumer<CreateContainerCmd> createContainerCmdConsumer, BiFunction<DockerClient, String, T> block) { checkAndPullImage(client, TINY_IMAGE); CreateContainerCmd createContainerCmd = client.createContainerCmd(TINY_IMAGE) .withLabels(DEFAULT_LABELS); createContainerCmdConsumer.accept(createContainerCmd); String id = createContainerCmd.exec().getId(); try { client.startContainerCmd(id).exec(); return block.apply(client, id); } finally { try { client.removeContainerCmd(id).withRemoveVolumes(true).withForce(true).exec(); } catch (NotFoundException | InternalServerErrorException ignored) { log.debug("", ignored); } } }
labels = new HashMap<>(labels != null ? labels : Collections.emptyMap()); labels.putAll(DockerClientFactory.DEFAULT_LABELS); createCommand.withLabels(labels);
createContainerCmd.withLabels(containerConfiguration.getLabels());
createContainerCmd.withLabels(containerConfiguration.getLabels());
createContainerCmd.withLabels(containerConfiguration.getLabels());
createContainerCmd.withLabels(containerConfiguration.getLabels());