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.
pull/52439/head
Felix Fontein 6 years ago committed by ansibot
parent e284a1546f
commit be3a47e2fe

@ -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/``."

@ -570,8 +570,19 @@ class AnsibleDockerClient(Client):
# 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)
if registry == 'docker.io':
# the name does not contain a registry, so let's see if docker.io works
lookup = "docker.io/%s" % name
# If docker.io is explicitly there in name, the image
# 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)
images = self._image_lookup(lookup, tag)

Loading…
Cancel
Save