首页 > 解决方案 > 容器之间的连接

问题描述

我建立烧瓶应用程序的图像。当我尝试从他们的容器发送请求以提供服务时,一切正常。然后我尝试从另一个容器发送请求。

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'))

标签: docker

解决方案


推荐阅读