diff --git a/flytekit/image_spec/image_spec.py b/flytekit/image_spec/image_spec.py index 4e5f103782..1aadac3bfd 100644 --- a/flytekit/image_spec/image_spec.py +++ b/flytekit/image_spec/image_spec.py @@ -104,7 +104,6 @@ def is_container(self) -> bool: return os.environ.get(_F_IMG_ID) == self.image_name() return True - @lru_cache def exist(self) -> bool: """ Check if the image exists in the registry. @@ -127,10 +126,14 @@ def exist(self) -> bool: return False except Exception as e: tag = calculate_hash_from_image_spec(self) - # if docker engine is not running locally - container_registry = DOCKER_HUB - if self.registry and "/" in self.registry: + # if docker engine is not running locally, use requests to check if the image exists. + if "localhost:" in self.registry: + container_registry = self.registry + elif self.registry and "/" in self.registry: container_registry = self.registry.split("/")[0] + else: + # Assume the image is in docker hub if users don't specify a registry, such as ghcr.io, docker.io. + container_registry = DOCKER_HUB if container_registry == DOCKER_HUB: url = f"https://hub.docker.com/v2/repositories/{self.registry}/{self.name}/tags/{tag}" response = requests.get(url)