File tree 1 file changed +13
-10
lines changed
1 file changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -128,21 +128,24 @@ def get_child_process_ids(pid):
128
128
return pids + get_child_process_ids (child_pid )
129
129
else :
130
130
return []
131
-
131
+
132
+
132
133
def get_docker_host ():
133
134
"""Discover remote docker host address (if applicable) or use "localhost"
134
-
135
- Use "docker context inspect" to read current docker host endpoint url
136
-
135
+
136
+ Use "docker context inspect" to read current docker host endpoint url,
137
+ url must start with "tcp://"
138
+
137
139
Args:
138
140
139
141
Returns:
140
- docker_host (str): Docker host DNS or IP
142
+ docker_host (str): Docker host DNS or IP address
141
143
"""
142
- try :
143
- docker_context_string = os .popen ("docker context inspect" ).read ()
144
- docker_context_host_url = json .loads (docker_context_string )[0 ]['Endpoints' ]['docker' ]['Host' ]
145
- docker_host = docker_context_host_url .split ("//" )[1 ].rsplit (":" )[0 ] if not docker_context_host_url .startswith ("unix" ) else "localhost"
146
- except :
144
+ docker_context_string = os .popen ("docker context inspect" ).read ()
145
+ docker_context_host_url = json .loads (docker_context_string )[0 ]["Endpoints" ]["docker" ]["Host" ]
146
+ parsed_url = urlparse (docker_context_host_url )
147
+ if parsed_url .hostname and parsed_url .scheme == "tcp" :
148
+ docker_host = parsed_url .hostname
149
+ else :
147
150
docker_host = "localhost"
148
151
return docker_host
You can’t perform that action at this time.
0 commit comments