1

I build image of flask app. When I try to send request from their container to service all is ok. Then I try to send request from another container.

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

And then do docker inspect web_server. Their all good. Then

docker attach client

import requests
req = requests.get('http://server:8000/health')

There is an error: Failed to establish new connection

How could I fix this problem?

There is Dockerfile of server image

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" ]

config file:

bind = '127.0.0.1:8000'
backlog = 1024
workers = 1
worker_class = 'sync'
worker_connections = 1000
timeout = 42
keepalive = 2
reload = True

Run flask+gunicor by : gunicorn -c config.py server:app

server.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()

Error log:

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'))
rnd
  • 67
  • 10
  • 2
    Is there a more detailed error message? Can you show the server code that sets up the network listener? (Is it obvious if it's listening to the container-private 127.0.0.1 localhost interface, or the 0.0.0.0 all-interfaces address?) – David Maze Jun 17 '21 at 14:04
  • 1
    @DavidMaze I add details – rnd Jun 17 '21 at 14:19
  • 2
    You need to `app.run(host='0.0.0.0')` in Flask, or else it won't be accessible outside its own container. The linked question has more details. – David Maze Jun 17 '21 at 14:21

0 Answers0