-
Notifications
You must be signed in to change notification settings - Fork 136
feat: fix api fetch error for docker client #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
(cherry picked from commit 57c4978)
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes Docker client connectivity issues on macOS by implementing fallback logic when the standard environment-based Docker connection fails. The solution adds a fallback mechanism that attempts to connect using the current Docker context configuration.
- Adds resilient Docker client initialization with environment and context-based fallback options
- Implements Docker context inspection to extract host endpoint information for connection fallback
- Modifies the Docker class constructor to accept an optional base_url parameter for flexibility
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| def __init__(self): | ||
| self.client = docker.from_env() | ||
| def __init__(self, base_url: str | None = None): | ||
| self.client = None |
Copilot
AI
Sep 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If Docker client initialization fails completely, self.client remains None, which will cause AttributeError when other methods try to use it. Consider raising an exception or implementing proper error handling in methods that use self.client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please raise an exception if the client is not initialised.
| print("Failed to connect to docker client from docker env") | ||
| pass | ||
|
|
||
| context_host = _docker_context_host() |
Copilot
AI
Sep 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function _docker_context_host() is called without checking if docker command is available on the system, which could cause subprocess errors on systems without Docker CLI installed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid point
gaganso
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! This makes the client robust. There are a few changes that would make it easy to maintain. Please let me know if you us know if you have any questions.
| def __init__(self): | ||
| self.client = docker.from_env() | ||
| def __init__(self, base_url: str | None = None): | ||
| self.client = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please raise an exception if the client is not initialised.
|
|
||
| import docker | ||
| import subprocess | ||
| import os |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be removed?
| return | ||
| except Exception: | ||
| print("Failed to connect to docker client from docker env") | ||
| pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be removed?
| self.client = env_client | ||
| return | ||
| except Exception: | ||
| print("Failed to connect to docker client from docker env") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a more descriptive error message including the base_url and the exception?
| print("Failed to connect to docker client from docker env") | ||
| pass | ||
|
|
||
| context_host = _docker_context_host() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid point
Trace API threading fix
gaganso
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please address my comments?
What
The Docker client cannot connect because it failed to fetch the Docker daemon for problem ID

k8s_target_port-misconfig-detection-1.Env
How
_docker_context_hostmethod to inspect and parse Docker context endpoints