Docker-java: With Docker 20.10.0 listImages filter no longer works

Created on 10 Dec 2020  路  5Comments  路  Source: docker-java/docker-java

With 20.10.0 docker removed the filter parameter when listing images.

https://docs.docker.com/engine/deprecated/#filter-param-for-imagesjson-endpoint

This causes

return dockerClient.listImagesCmd()
  .withImageNameFilter("mongo:4.2")
  .exec()
  .stream()
  .findFirst()
  .map(Image::getId);

to return the ID of the first image out of ALL images.

My current workaround for this is

try{
  return Optional.ofNullable(dockerClient.inspectImageCmd("mongo:4.2").exec().getId());
} catch (final NotFoundException e) {
  return Optional.empty();
}

All 5 comments

Yes, that's correct (they removed the deprecated param)

There are several options:

  1. set the API version 1.40 or lower (make sure to update to docker-java 3.2.7)
  2. Use inspectImageCmd instead of list + filter
  3. getFilters().put("reference", Arrays.asList("my/image))

Great! Wasn't aware that 3.2.7 is already available.

I couldn't find it on Maven central.
I assume it will be published within the next days?

Thank you for providing the 3rd method. I wasn't aware of this.

(edit) Just noticed that the release happened during the investigation of the issue I had.
https://github.com/docker-java/docker-java/releases/tag/3.2.7

Happy to help!

The release is on jcenter amd will be synced to Maven Central soon (later today)

@bsideup Given the original issue example, how would it look like in 3 cases you have suggested, sorry?

@bsideup Given the original issue example, how would it look like in 3 cases you have suggested, sorry?

ListImagesCmd listImagesCmd = dockerClient.listImagesCmd();
listImagesCmd.getFilters().put("reference", Arrays.asList("my/image"));
List<Image> images = listImagesCmd.exec();
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ybouhjira picture ybouhjira  路  7Comments

Sakib37 picture Sakib37  路  3Comments

alecharp picture alecharp  路  3Comments

Hixon10 picture Hixon10  路  4Comments

lispyclouds picture lispyclouds  路  3Comments