Skip to content

Commit 9f4f949

Browse files
committed
feature: Add support for remote docker host
1 parent 3e73133 commit 9f4f949

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/sagemaker/local/utils.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,24 @@ def get_child_process_ids(pid):
128128
return pids + get_child_process_ids(child_pid)
129129
else:
130130
return []
131-
131+
132+
132133
def get_docker_host():
133134
"""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+
137139
Args:
138140
139141
Returns:
140-
docker_host (str): Docker host DNS or IP
142+
docker_host (str): Docker host DNS or IP address
141143
"""
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:
147150
docker_host = "localhost"
148151
return docker_host

0 commit comments

Comments
 (0)