I have a Dockerfile which I want to run some tests inside of as part of a multistage build. The tests attempt to make a connection to localhost, however it appears that they're not able to connect to the specific port (which is ready on the host machine) inside the RUN command of the Dockerfile. Is such a thing possible, and if so how do I achieve it? Obviously external connections can be made at build time (to download dependencies and such) and loopbacks at run time
FROM python:3.7-alpine as tester
COPY . .
RUN python -m unittest discover
And for reference, the Python code checking the connection
def setUp():
timeout = 120.0
port = 15903
host = 'localhost'
start_time = time.perf_counter()
while True:
try:
with socket.create_connection((host, port), timeout=timeout):
break
except OSError as ex:
time.sleep(1.0)
if time.perf_counter() - start_time >= timeout:
raise TimeoutError('Waited too long for the port {} on host {} to start accepting connections.'.format(port, host)) from ex