I want to run a dockerized flask server locally and access any routes that I define in it. Setup to reproduce my problem:
app.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'Hello World!'
Dockerfile
from python:3.7-alpine
COPY app.py app.py
RUN pip install flask
CMD [ "flask", "run" ]
Building this container works fine. Following the documentation and some in-depth examples, running it with docker run -p 5000:5000 flask
should do the trick. It starts the container and looks good:
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
And docker ps
shows me that the port mapping also seems to work:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0581bf3af0ea flask "flask run" 25 seconds ago Up 24 seconds 0.0.0.0:5000->5000/tcp nervous_brown
But I only get a 404 when I try to reach the site in my browser.
Funnily enough, running the image with docker run --net=host flask
does work, but I'd rather not use it.
I'm really bad at understanding how networks work, what am I doing wrong?