I have python flask application that listens to another microservice running on 8080. When I run as flask application it is able to get from http://localhost:8080/users.
But when I run inside docker it fails with
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /users (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f53804b5dc0>: Failed to establish a new connection: [Errno 111] Connection refused'))
at line:
File "/alert.py", line 45, in get_users
r = requests.get('http://localhost:8080/users',verify=False)
This is my main code:
if __name__ == '__main__':
app.logger.setLevel(logging.INFO)
data = create_data()
port = os.getenv('PORT')
app.run(debug=True, host='0.0.0.0', port=port)
Docker script:
#!/bin/bash
docker build -t covid_service .
docker run -p 5000:5000 covid_service
Docker file:
FROM python:3
ADD alert.py /
RUN pip install flask
RUN pip install requests
EXPOSE 5000
CMD [ "python", "./alert.py" ]
Any help please