title: Why can't I connect to the flask server in docker container?
body: <p>My virtualmachine's os is CentOS 7 and its docker version is 19.03.8. I create my own image <code>python-image</code>. I run the following codes to create a new container:</p>
  
  <pre><code>docker run -it -p 5555:5000 python-image /bin/bash
  </code></pre>
  
  <p>In the container, a python script named <code>test.py</code> is as follows:</p>
  
  <pre><code># test.py
  from flask import Flask
  
  app = Flask(__name__)
  
  @app.route('/')
  def func():
      return "Hello docker!"
  
  
  if __name__ == '__main__':
      app.run('0.0.0.0', port=5000)
  </code></pre>
  
  <p>Then I run <code>python test.py</code> and up the container.</p>
  
  <p>In host shell, I run <code>curl http://127.0.0.1:5555/</code> and it prints:</p>
  
  <pre><code>curl: (56) Recv failure: Connection reset by peer
  </code></pre>
  
  <p>I know that if specify <code>--network</code> as <code>host</code> when creating the container:</p>
  
  <pre><code>docker run -it --network host python-image /bin/bash
  </code></pre>
  
  <p>Starting the server and running <code>curl http://127.0.0.1:5555/</code> in host will get the expected information. I wonder what should I do when keep default value of <code>--network</code> to get the same result.</p>