title: How to publish flask port from container to host
body: <p>I want to run a dockerized flask server locally and access any routes that I define in it. Setup to reproduce my problem:</p>
  
  <p><strong>app.py</strong></p>
  
  <pre class="lang-py prettyprint-override"><code>from flask import Flask
  
  app = Flask(__name__)
  
  @app.route('/')
  def index():
      return 'Hello World!'
  
  </code></pre>
  
  <p><strong>Dockerfile</strong></p>
  
  <pre><code>from python:3.7-alpine
  
  COPY app.py app.py
  
  RUN pip install flask
  
  CMD [ "flask", "run" ]
  </code></pre>
  
  <p>Building this container works fine. Following <a href="https://docs.docker.com/engine/reference/commandline/run/" rel="nofollow noreferrer">the documentation</a> and <a href="https://docs.docker.com/network/links/" rel="nofollow noreferrer">some in-depth examples</a>, running it with <code>docker run -p 5000:5000 flask</code> should do the trick. It starts the container and looks good:</p>
  
  <pre><code>* 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)
  </code></pre>
  
  <p>And <code>docker ps</code> shows me that the port mapping also seems to work:</p>
  
  <pre><code>CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                    NAMES
  0581bf3af0ea        flask               "flask run"         25 seconds ago      Up 24 seconds       0.0.0.0:5000-&gt;5000/tcp   nervous_brown
  </code></pre>
  
  <p>But I only get a 404 when I try to reach the site in my browser.</p>
  
  <p>Funnily enough, running the image with <code>docker run --net=host flask</code> does work, but I'd rather not use it.</p>
  
  <p>I'm really bad at understanding how networks work, what am I doing wrong?</p>