【发布时间】:2020-07-29 20:42:06
【问题描述】:
我有 python 烧瓶应用程序,它侦听在 8080 上运行的另一个微服务。当我作为烧瓶应用程序运行时,它能够从 http://localhost:8080/users 获取。
但是当我在 docker 内运行时它失败了
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'))
在线:
File "/alert.py", line 45, in get_users
r = requests.get('http://localhost:8080/users',verify=False)
这是我的主要代码:
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 脚本:
#!/bin/bash
docker build -t covid_service .
docker run -p 5000:5000 covid_service
Docker 文件:
FROM python:3
ADD alert.py /
RUN pip install flask
RUN pip install requests
EXPOSE 5000
CMD [ "python", "./alert.py" ]
请帮忙
【问题讨论】: