|
14 | 14 | """Module for LocalDockerModelServerRunner.""" |
15 | 15 |
|
16 | 16 | import os |
| 17 | +import subprocess |
17 | 18 | import time |
18 | 19 | from typing import Any, Dict, Optional |
19 | 20 |
|
@@ -65,10 +66,15 @@ def _find_host_port(ports: Dict[str, Any], container_port: int) -> str: |
65 | 66 | Raises: |
66 | 67 | ValueError: No corresponding host port was found. |
67 | 68 | """ |
| 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 | + |
68 | 74 | mappings = ports.get('{}/tcp'.format(container_port), []) |
69 | 75 | for mapping in mappings: |
70 | 76 | if mapping['HostIp'] == '0.0.0.0': |
71 | | - return mapping['HostPort'] |
| 77 | + return ip_address, mapping['HostPort'] |
72 | 78 | else: |
73 | 79 | raise ValueError( |
74 | 80 | 'No HostPort found for ContainerPort={} (all port mappings: {})' |
@@ -146,9 +152,11 @@ def WaitUntilRunning(self, deadline): |
146 | 152 | continue |
147 | 153 | # The container is running :) |
148 | 154 | 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) |
152 | 160 | return |
153 | 161 | # Docker status is one of {'created', 'restarting', 'running', 'removing', |
154 | 162 | # 'paused', 'exited', or 'dead'}. Status other than 'created' and |
|
0 commit comments