Closed
Description
Hello there everyone, I'm instrumenting a pytest
suite to run end-to-end tests against our repository manager and one of the helper functions I have in place is this one, that logs in and attempts to pull a container image:
def pull_docker_image(self, image) -> bool:
"""
Pull a Docker image from Nexus repository
Args:
image: Full image name including registry, repository and tag
Returns:
bool: True if pull successful, False otherwise
Raises:
Exception: If image pull fails.
"""
try:
registry_url = self.base_url.replace("https://", "")
home_directory = os.environ.get("HOME")
docker_socket_path_list = [
Path(f"unix:///{home_directory}/.orbstack/run/docker.sock"), # Orbstack
Path("unix:///run/docker.sock"), # Linux default
Path("unix:///var/run/docker.sock"), # macOS default
]
for docker_socket_path in docker_socket_path_list:
if docker_socket_path.is_socket():
break
client = docker.DockerClient(base_url=docker_socket_path)
client.login(
username=self.username, password=self.password, registry=registry_url
)
client.images.pull(image)
return True
except Exception as e:
raise Exception(f"Unexpected error pulling image {image}: {str(e)}")
But it fails to do so, here's the error that pytest
bubbles up:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../.venv/foo/lib/python3.12/site-packages/docker/client.py:45: in __init__
self.api = APIClient(*args, **kwargs)
../../../.venv/foo/lib/python3.12/site-packages/docker/api/client.py:146: in __init__
base_url = utils.parse_host(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
addr = PosixPath('unix:/var/run/docker.sock'), is_win32 = False, tls = False
def parse_host(addr, is_win32=False, tls=False):
# Sensible defaults
if not addr and is_win32:
return DEFAULT_NPIPE
> if not addr or addr.strip() == 'unix://':
E AttributeError: 'PosixPath' object has no attribute 'strip'
../../../.venv/foo/lib/python3.12/site-packages/docker/utils/utils.py:237: AttributeError
I'm using docker==7.1.0
, btw.
What am I missing here?
Metadata
Metadata
Assignees
Labels
No labels