File tree 1 file changed +3
-1
lines changed
1 file changed +3
-1
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,7 @@ def get_docker_host():
133
133
"""Discover remote docker host address (if applicable) or use "localhost"
134
134
135
135
Use "docker context inspect" to read current docker host endpoint url
136
+ url must start with "tcp://"
136
137
137
138
Args:
138
139
@@ -142,7 +143,8 @@ def get_docker_host():
142
143
try :
143
144
docker_context_string = os .popen ("docker context inspect" ).read ()
144
145
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
+ parsed_url = urlparse (docker_context_host_url )
147
+ docker_host = parsed_url .hostname if parsed_url .hostname and parsed_url .scheme == "tcp" else "localhost"
146
148
except :
147
149
docker_host = "localhost"
148
150
return docker_host
You can’t perform that action at this time.
0 commit comments