Skip to content
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

Support multiple docker socket #2471

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add TODO
  • Loading branch information
loopback-kr committed Jun 19, 2023
commit 4d6052e79e3b70bf1307b97934811e8fdef6ec77
8 changes: 4 additions & 4 deletions glances/plugins/containers/engines/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,22 +215,22 @@ class DockerContainersExtension:

CONTAINER_ACTIVE_STATUS = ['running', 'paused']

def __init__(self):
def __init__(self, server_url:str = 'unix://var/run/docker.sock'):
if import_docker_error_tag:
raise Exception("Missing libs required to run Docker Extension (Containers) ")

self.client = None
self.ext_name = "containers (Docker)"
self.stats_fetchers = {}

self.connect()
self.connect(server_url)

def connect(self):
def connect(self, base_url:str = 'unix://var/run/docker.sock'):
"""Connect to the Docker server."""
# Init the Docker API Client
try:
# Do not use the timeout option (see issue #1878)
self.client = docker.from_env()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test if base_urls is empty then use from_env() else use the base_urls list instead

self.client = docker.DockerClient(base_url)
except Exception as e:
logger.error("{} plugin - Can't connect to Docker ({})".format(self.ext_name, e))
self.client = None
Expand Down
6 changes: 3 additions & 3 deletions glances/plugins/containers/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self, args=None, config=None):
self.args = args

# Default config keys
self.config = config
self.config = config # TODO: need to debug this point

# We want to display the stat in the curse interface
self.display_curse = True
Expand All @@ -82,7 +82,7 @@ def __init__(self, args=None, config=None):
if import_podman_error_tag:
self.podman_client = None
else:
self.podman_client = PodmanContainersExtension(podman_sock=self._podman_sock())
self.podman_client = PodmanContainersExtension(podman_sock=self._podman_sock()) # TODO: podman also
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IS it also possible to have multiple socket for Podman ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolargo
Yep.
In fact its more common to have custom socket's in the podman ecosystem.


# Sort key
self.sort_key = None
Expand Down Expand Up @@ -157,7 +157,7 @@ def update(self):

if self.input_method == 'local':
# Update stats
stats_docker = self.update_docker() if self.docker_extension else {}
stats_docker = self.update_docker() if self.docker_extension else {} # TODO: need to concat all docker client
stats_podman = self.update_podman() if self.podman_client else {}
stats = {
'version': stats_docker.get('version', {}),
Expand Down