So, I created a sample Flask app, which I dockerized for our Kubernetes environment. But when I try to run my app locally, I get an Address already in use
error. It's a very simple web server in Flask:
My app.py
if __name__ == "__main__":
ENV = os.environ.get('env', INT)
PORT = os.environ.get('flaskPort', PORT)
logging.info(f" **** ENV={ENV} PORT={PORT} **** ")
app.run(host="0.0.0.0", port=PORT, debug=True)
and here's the error I see when I run python3 src/app.py
:
* Serving Flask app "MOCK EHR FHIR SERVER" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
Traceback (most recent call last):
File "/Users/x/git/mock-python-server/src/app.py", line 136, in <module>
app.run(host="0.0.0.0", port=PORT, debug=True)
File "/Users/x/git/mock-python-server/venv/lib/python3.9/site-packages/flask/app.py", line 990, in run
run_simple(host, port, self, **options)
File "/Users/x/git/mock-python-server/venv/lib/python3.9/site-packages/werkzeug/serving.py", line 1030, in run_simple
s.bind(server_address)
OSError: [Errno 48] Address already in use
I don't have anything running on 5000
. But, when I change the host
to 127.0.0.1
, it starts up just fine. Do I always have to change it to 127.0.0.1
when I run it from the cmd line and 0.0.0.0
when it's in a container?
question from:
https://stackoverflow.com/questions/66054244/flask-app-does-not-start-with-0-0-0-0-host-locally 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…