Skip to content

Commit 5b012ff

Browse files
committed
feature: Support for remote docker host
1 parent 6181117 commit 5b012ff

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/sagemaker/local/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def get_docker_host():
133133
"""Discover remote docker host address (if applicable) or use "localhost"
134134
135135
Use "docker context inspect" to read current docker host endpoint url
136+
url must start with "tcp://"
136137
137138
Args:
138139
@@ -142,7 +143,8 @@ def get_docker_host():
142143
try:
143144
docker_context_string = os.popen("docker context inspect").read()
144145
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"
146148
except:
147149
docker_host = "localhost"
148150
return docker_host

0 commit comments

Comments
 (0)