docker_common: improve image finding methods (#44692)

* Work around problem with Docker daemon that sometimes won't find image if prefixed with docker.io repo name.

* When tring library/xxx, docker-py also doesn't sometimes find the image.

* Add changelog.
This commit is contained in:
Felix Fontein 2019-02-17 20:28:40 +01:00 committed by ansibot
parent e284a1546f
commit be3a47e2fe
2 changed files with 17 additions and 4 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "docker_container, docker_image, docker_image_facts - also find local image when image name is prefixed with ``docker.io/library/`` or ``docker.io/``."

View file

@ -570,8 +570,19 @@ class AnsibleDockerClient(Client):
# In API <= 1.20 seeing 'docker.io/<name>' as the name of images pulled from docker hub # In API <= 1.20 seeing 'docker.io/<name>' as the name of images pulled from docker hub
registry, repo_name = auth.resolve_repository_name(name) registry, repo_name = auth.resolve_repository_name(name)
if registry == 'docker.io': if registry == 'docker.io':
# the name does not contain a registry, so let's see if docker.io works # If docker.io is explicitly there in name, the image
lookup = "docker.io/%s" % name # isn't found in some cases (#41509)
self.log("Check for docker.io image: %s" % repo_name)
images = self._image_lookup(repo_name, tag)
if len(images) == 0 and repo_name.startswith('library/'):
# Sometimes library/xxx images are not found
lookup = repo_name[len('library/'):]
self.log("Check for docker.io image: %s" % lookup)
images = self._image_lookup(lookup, tag)
if len(images) == 0:
# Last case: if docker.io wasn't there, it can be that
# the image wasn't found either (#15586)
lookup = "%s/%s" % (registry, repo_name)
self.log("Check for docker.io image: %s" % lookup) self.log("Check for docker.io image: %s" % lookup)
images = self._image_lookup(lookup, tag) images = self._image_lookup(lookup, tag)