Skip to content

Commit d87e75b

Browse files
anuartbtfx-copybara
authored andcommitted
no-op
PiperOrigin-RevId: 548556494
1 parent 96d4e43 commit d87e75b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

tfx/components/infra_validator/model_server_runners/local_docker_runner.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"""Module for LocalDockerModelServerRunner."""
1515

1616
import os
17+
import subprocess
1718
import time
1819
from typing import Any, Dict, Optional
1920

@@ -65,10 +66,15 @@ def _find_host_port(ports: Dict[str, Any], container_port: int) -> str:
6566
Raises:
6667
ValueError: No corresponding host port was found.
6768
"""
69+
command = '/sbin/ip route|awk \'/default/ { print $3 }\''
70+
ip_address = subprocess.check_output(
71+
command, shell=True).decode('utf-8').strip()
72+
logging.info('Container IP address: %s', ip_address)
73+
6874
mappings = ports.get('{}/tcp'.format(container_port), [])
6975
for mapping in mappings:
7076
if mapping['HostIp'] == '0.0.0.0':
71-
return mapping['HostPort']
77+
return ip_address, mapping['HostPort']
7278
else:
7379
raise ValueError(
7480
'No HostPort found for ContainerPort={} (all port mappings: {})'
@@ -146,9 +152,11 @@ def WaitUntilRunning(self, deadline):
146152
continue
147153
# The container is running :)
148154
if status == 'running':
149-
host_port = _find_host_port(self._container.ports,
150-
self._serving_binary.container_port)
151-
self._endpoint = 'localhost:{}'.format(host_port)
155+
ip_address, host_port = _find_host_port(
156+
self._container.ports,
157+
self._serving_binary.container_port)
158+
159+
self._endpoint = '{}:{}'.format(ip_address, host_port)
152160
return
153161
# Docker status is one of {'created', 'restarting', 'running', 'removing',
154162
# 'paused', 'exited', or 'dead'}. Status other than 'created' and

0 commit comments

Comments
 (0)