0

I have tested my python app for two different ports container1(5000) and container2(5100). It returns 'The requested URL was not found on this server'

container1 -> app.py

import flask
import requests
app = flask.Flask(__name__)

@app.route('/definition', methods=['POST'])
def gateKeeper():
    request_data = flask.request.get_json()
    text = request_data['text']
    if text == None or len(text) == 0:
        output = {
            "text":text,
            "error":"Invalid JSON input."
        }
    else:
        wordToSend = {"text":text.strip().lower()}
        res = requests.post('http://container2:5100/getDefinition', json=wordToSend)
        output = res.json()
    return output

if __name__=="__main__":

    app.run(port=5000)

container2 -> app.py

import flask

app = flask.Flask(__name__)

@app.route('/getDefinition', methods=['POST'])
def gateKeeper():
    request_data = flask.request.get_json()
    text = request_data['text']
    if text == None or len(text) == 0:
        output = {
            "text":text
            "error":"Invalid JSON input."
        }
    else:
        wordToSend = {"text":text.strip().lower()}
        res = requests.post('http://localhost:5000/tests/endpoint', json=wordToSend)
        output = res.json

    return output

if __name__=="__main__":
    app.run(port=5100)

Run this command for the run containers:

docker run -dit --name container1 -p 5000:80 httpd:2.4
docker run -dit --name container2 -p 5100:80 httpd:2.4

Output: enter image description here

Nikund Lathiya
  • 79
  • 2
  • 10
  • 2
    `httpd:2.4` is a pure webserver image. How does your app get into the container? – Klaus D. Feb 04 '22 at 05:26
  • 1
    The code as you've shown it will also have the problem in [Deploying a minimal flask app in docker - server connection issues](https://stackoverflow.com/questions/30323224/deploying-a-minimal-flask-app-in-docker-server-connection-issues). – David Maze Feb 04 '22 at 10:57

0 Answers0