0

The app runs, but when I try to go to the link @ http://172.17.0.2:5000/ it times out.

relevant code:

app = Flask(__name__)
@app.route('/')
def index():
    return "hullo"

I have also tried it with and without this code underneath which is what other stackoverflow responses to questions similar to mine have suggested, but it doesn't work:

 if __name__ == '__main__':
   app.run(host ='0.0.0.0')

Dockerfile:

FROM python:3.9.6-slim-buster
WORKDIR /project
RUN python -m pip install --upgrade pip
RUN pip install -U Flask Flask-WTF Flask-SQLAlchemy DateTime python-dotenv mysql-connector-python
COPY . .
CMD [ "python3", "-m" , "flask", "run", "--host", "0.0.0.0"]

Run cmd:

docker run --publish 5000:5000 testbon5

This is practically copy and pasted from the official docs tutorial. Is there something I'm doing wrong?

3Ring
  • 49
  • 3
  • have you tried `127.0.0.1` instead? – Teejay Bruno Aug 10 '21 at 17:14
  • I'm not very fluent in networking, so I don't know why that would work, but I tried it and it didn't. Flask still starts up, but you get an empty response when going to the url. thanks for the thought though. – 3Ring Aug 10 '21 at 17:23
  • What OS are you using? I'm able to copy and paste your code and access it from my browser. – Teejay Bruno Aug 10 '21 at 17:35
  • someone on the docker slack helped me out. I posted the answer below. thanks for trying! – 3Ring Aug 10 '21 at 17:39

1 Answers1

2

figured it out. from a very nice person on slack.

I needed to type "localhost:/5000" into my address bar. It confused me because I have always access the site I'm working on through the flask log which in this case is:

 * Serving Flask app 'project/app.py' (lazy loading)
 * Environment: development
 * Debug mode: on
 * Running on all addresses.
   WARNING: This is a development server. Do not use it in a production deployment.
 * Running on http://172.17.0.2:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!

I guess since it's running in the container that address doesn't work anymore. Hopefully this helps anyone else going through growing pains like me while learning docker.

3Ring
  • 49
  • 3