0

Context:

  • System: Win10 + WSL2 (Development environment)
  • I'm new to both Flask and Docker

Problem:

  • If I don't run any docker containers, the Flask app I'm running on localhost can be connected from a browser (the app is run without using a container)

  • If I already have containers running with, say, Elasticsearch, or another Flask app, then the Flask app I'm running on localhost can NOT be connected anymore (again, this app is run without using a container)

  • On my terminal, the app still seems to be running properly

  • On my browser, it simply says "127.0.0.1 refused to connect"

  • The app is run simply using "flask run", and messages displayed on my terminal looks like this:


  • Serving Flask app "microblog.py"
  • Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
  • Debug mode: off [2021-07-01 21:42:05,107] INFO in init: Microblog startup

Question:

  • Why would this happen - running containers messed up non-container Flask app listening to ports?
  • How can I fix this?

Thanks!

Wei
  • 37
  • 5
  • 1
    How do you run your app? – Star Jul 02 '21 at 01:43
  • 2
    It's hard to provide any meaningful answers to your question without seeing your flask app and/or the Dockerfile. Please provide some details about how `app.run` is called, as well as the Dockerfile. – Abdou Jul 02 '21 at 01:44
  • Just updated my post to include how I run my app. The containers that interfere with the flask app was just using images (Elasticsearch etc) I pulled from docker hub - no Dockerfile involved. – Wei Jul 02 '21 at 01:56
  • Long story short: Docker containers run in their own network namespaces. Are you forwarding any ports between the running containers and your host machine? Essentially, when you call `docker run`, are you using the `-p` option? If so, what does that look like? – Abdou Jul 02 '21 at 03:06
  • If it says "running on 127.0.0.1" it won't be accessible from outside its own container; it needs to listen on the special 0.0.0.0 "all interfaces" IP address, and the linked question describes how to address this for Flask. (For your future questions, make sure to include enough code in the question to reproduce the problem; in this case the error message points at a specific problem but that's not always true.) – David Maze Jul 02 '21 at 10:48

0 Answers0