docker - 容器之间的连接
问题描述
我建立烧瓶应用程序的图像。当我尝试从他们的容器发送请求以提供服务时,一切正常。然后我尝试从另一个容器发送请求。
docker network create web_server --driver bridge
docker run -dit --name server --network web_server test_container
docker run -dit --name client --network web_server python:3.8.9-slim-buster
然后做docker inspect web_server
。他们都很好。然后
docker attach client
import requests
req = requests.get('http://server:8000/health')
有一个错误:Failed to establish new connection
我该如何解决这个问题?
有Dockerfile
服务器镜像
FROM registry.access.redhat.com/ubi8:8.4
WORKDIR /opt/pipeline
COPY . .
ARG MODEL=<link_to_repo>
RUN git clone ${MODEL} model
RUN python setup.py install
EXPOSE 8000
CMD [ "sh", "./app.sh" ]
配置文件:
bind = '127.0.0.1:8000'
backlog = 1024
workers = 1
worker_class = 'sync'
worker_connections = 1000
timeout = 42
keepalive = 2
reload = True
通过以下方式运行烧瓶+gunicor:
gunicorn -c config.py server:app
服务器.py:
from flask import Flask, jsonify, request
app = Flask(__name__)
@app.route(rule='/health', methods=['GET'])
def health():
return '200'
if __name__ == "__main__":
app.run()
错误日志:
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='server', port=8000): Max retries exceeded with url: /health (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f4b3690de20>: Failed to establish a new connection: [Errno 111] Connection refused'))
解决方案
推荐阅读
- kubernetes - 使用 Istio 将请求路由到外部服务(Webhooks)
- ruby - Ruby-Heroku 如何创建 procfile
- function - 如何在函数中使用泛型并在 rust 中使用模式匹配?
- google-app-engine - 如何通过 Google App engine Flex 将 Google Cloud SQL 连接到僵尸网络核心应用程序?
- ios - 启动 react-native run-ios 时 Native-Module 不能为 Null
- java - 在java中,如何在不同数据类型的数组中创建一个数组
- testing - 将以太坊从账户转移到合约时“耗尽气体”
- kotlin - 我创建类的对象并得到一个错误“线程“主”java.lang.StackOverflowError中的异常”
- c# - C#8.0:具有默认实现的接口的受保护属性
- javascript - 如何接收用户输入的日期并将其与 date() javascript 函数匹配?