public String getLatestDownloadedImage(String imageName) { List<Image> images; try { images = dockerClient.listImages(DockerClient.ListImagesParam.byName(imageName)); if (images.isEmpty()) { logger.error(nodeId + " A downloaded docker-selenium image was not found!"); return imageName; } for (int i = images.size() - 1; i >= 0; i--) { if (images.get(i).repoTags() == null) { images.remove(i); } } images.sort((o1, o2) -> o2.created().compareTo(o1.created())); return images.get(0).repoTags().get(0); } catch (DockerException | InterruptedException e) { logger.warn(nodeId + " Error while executing the command", e); ga.trackException(e); } return imageName; }
List<Image> images = dockerClient.listImages(DockerClient.ListImagesParam.byName(image)); if (images.size() == 0) {
public Optional<Image> findImage() { try { List<Image> images = dockerClient.listImages(DockerClient.ListImagesParam.allImages()); for (Image image : images) { if (image.repoTags() != null) { for (String tag : image.repoTags()) { if (tag.equals(imageName)) { return Optional.of(image); } } } } } catch (DockerException | InterruptedException e) { LOG.error("Unable to retrieve a list of Docker images", e); } return Optional.empty(); }
private Optional<Image> findImage(DockerClient docker, String imageName) { try { List<Image> images = docker.listImages(DockerClient.ListImagesParam.allImages()); for (Image image : images) { if (image.repoTags() != null) { for (String tag : image.repoTags()) { if (tag.equals(imageName)) { return Optional.of(image); } } } } } catch (DockerException | InterruptedException e) { LOG.error("Unable to retrieve a list of Docker images", e); } return Optional.empty(); }
private boolean imageAvaliable(DockerClient dockerClient, String imageName) throws DockerException, InterruptedException { String imageNameWithTag = imageNameWithTag(imageName); List<Image> listImages = dockerClient.listImages(ListImagesParam.danglingImages(false)); for (Image image : listImages) { if (image.repoTags() != null && image.repoTags().contains(imageNameWithTag)) { log.debug("image '{}' found", imageNameWithTag); return true; } } log.debug("image '{}' not found", imageNameWithTag); return false; }
/** * List all the images available * * @return * @throws DockerException * @throws InterruptedException */ private List<DockerImageInfo> getImagesInfo(List<DockerInfo> containers) throws DockerException, InterruptedException { return client.listImages() .stream() .map(i -> { DockerImageInfo info = new DockerImageInfo(); info.setId(i.id()); info.setTag(Optional.ofNullable(i.repoTags()).map(tags -> tags.stream().collect(Collectors.joining(", "))).orElse("")); info.setSize(ByteUtils.humanReadableByteCount(i.size(), true)); ZonedDateTime created = Instant.ofEpochSecond(Long.parseLong(i.created())).atZone(ZoneId.systemDefault()); info.setCreated(created.format(DateTimeFormatter.RFC_1123_DATE_TIME)); String usedBy = containers .stream() .filter(c -> c.imageId.equalsIgnoreCase(i.id())) .map(c -> c.names.stream().collect(Collectors.joining(", "))) .collect(Collectors.joining(", ")); info.setUsedBy(usedBy); return info; }) .collect(Collectors.toList()); }
public static String findDockerImage(String imageName, DockerClient docker) { if (docker == null) { throw new RuntimeException("Docker client has not been initialized. No docker image can be found."); } try { List<Image> allImages = docker.listImages(DockerClient.ListImagesParam.allImages()); String imageId = null; for (Image image : allImages) { if (image.repoTags() != null && image.repoTags().contains(imageName)) { imageId = image.id(); break; } } if (imageId == null) { throw new RuntimeException("There was a problem when looking for the docker image with argument \""+imageName+"\": no image has been found."); } return imageId; } catch (InterruptedException|DockerException e) { throw new RuntimeException("Error while looking for the docker image",e); } }
List<Image> images = client.listImages(); boolean isImageExist = false; for (Image image : images) {
@Override public void start(WorkflowInstance workflowInstance, RunSpec runSpec) { final String imageTag = runSpec.imageName().contains(":") ? runSpec.imageName() : runSpec.imageName() + ":latest"; final ContainerCreation creation; try { boolean found = false; for (Image image : client.listImages()) { found |= image.repoTags().contains(imageTag); } if (!found) { client.pull(imageTag, System.out::println); // blocking } final ContainerConfig containerConfig = ContainerConfig.builder() .image(imageTag) .cmd(runSpec.args()) .build(); creation = client.createContainer(containerConfig, runSpec.executionId()); client.startContainer(creation.id()); } catch (DockerException | InterruptedException e) { throw new RuntimeException(e); } inFlight.put(creation.id(), workflowInstance); LOG.info("Started container with id " + creation.id() + " and name " + runSpec.executionId()); }