ConnectionError: HTTPConnectionPool(host='172.30.0.3', port=5051): Max retries exceeded with url for flask docker

Viewed 129

Im a begginer in docker and flask and am trying to build an arthimatic microservice.I'm trying to build seperate flask applications for addition,substraction etc and communicating with them from my landing-service.For now I am only trying to implement Addition service

landing-Service Code

 @app.route('/', methods=['POST', 'GET'])
 def index():
    # Only process the code if the Submit button has been clicked.
    if request.form.get("submit_button") != None:
        number_1 = int(request.form.get("first"))
        number_2 = int(request.form.get('second'))
        operation = request.form.get('operation')
        result = 0
        if operation == 'add':
            response = requests.get(f"http://localhost:5051/?operator_1={number_1}&operator_2={number_2}")
            result = response.text
    
        flash(f'The result of operation {operation} on {number_1} and {number_2} is {result}')

    return render_template('index.html')

if __name__ == '__main__':
app.run(
    debug=True,
    port=5050,
    host="0.0.0.0"
)

Addition service code:

class Addition(Resource):
   def get(self):
      if request.args.get('operator_1)!=None and request.args.get('operator_2')!=None:
         operator_1 = int(request.args.get('operator_1'))
         operator_2 = int(request.args.get('operator_2'))
         return operator_1+operator_2


   api.add_resource(Addition,'/')
   if __name__=='__main__':
       app.run(debug=True,
               port=5051,
               host="0.0.0.0"
       )

Docker compose file

version: '3.3'  # version of compose format

services:
   landing-service:
      build: ./landing  # path is relative to docker-compose.yml location
      hostname: landing-service
      ports:
        - 5050:5050  # host:container
      networks:
        sample:
          aliases:
            - landing-service
   addition-service:
     build: ./addition  # path is relative to docker-compose.yml location
     hostname: addition-service
     ports:
       - 5051:5051  # host:container
     networks:
       sample:
         aliases:
           - addition-service
networks:
  sample:

I am getting .ConnectionError: HTTPConnectionPool(host='172.30.0.3', port=5051): Max retries exceeded with url when i use docker-compose up.The applications work when i use them from command line and my lannding service is able to communicate with localhost:5051 but i am unable to communicate between them when i use docker-compose....

0 Answers
Related