0

I searched for this issue but noticed it is people running a flask script inside a docker container, but not a flask script on their local machine and trying to curl it from within their docker container.

I have a simple flask script and it just says hello, but when i use curl 127.0.0.1:5000, i get a connection refused. It works if i do 192.168.0.15:5000, but that isn't what i want. I am using a mac os.

I tried adding "0.0.0.0" to the flask script instead of "127.0.0.1" but no luck.

This is my flask script:

    from flask import Flask, redirect, url_for, request
app = Flask(__name__)

@app.route('/post',methods = ['POST'])
def post():
   for key in request.form:
     print ('form parameter: '+key + " form value: "+request.form[key])
   return "hello"

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

When i open docker tomcat terminal and try to curl localhost:5000, connection refused. However, i can curl the ip the web server is running on, but i want to be able to curl localhost or 127.0.0.1. Thanks a lot.

  • Please provide enough code so others can better understand or reproduce the problem. – Community May 09 '23 at 18:03
  • If you flask script is running on your host, then it will not be available at `127.0.0.1` inside a container (that address means "in this container"). You need to use the ip address of a host interface. – larsks May 09 '23 at 23:25

0 Answers0