title: socket.error:[errno 99] cannot assign requested address : flask and python
body: <p>I am having the same problem like <a href="https://stackoverflow.com/questions/26280868/flask-cannot-assign-requested-address?noredirect=1&amp;lq=1">here</a> and <a href="https://stackoverflow.com/questions/19246103/socket-errorerrno-99-cannot-assign-requested-address-and-namespace-in-python">here</a></p>
  
  <p>I am Trying to run a flask app inside docker container.It works fine with '0.0.0.0' but it throws error with my ip address</p>
  
  <p>I am behind a corporate proxy. When i checked my ip address with ipconfig, it showed IP Address as : <code>10.***.**.**</code> And I am using docker toolbox where my container ip is 172.17.0.2 and VM IP Address is 192.168.99.100.</p>
  
  <p>I have a flask app running inside this docker with host </p>
  
  <pre><code>if __name__ == "__main__":
      app.run(host= '0.0.0.0')
  </code></pre>
  
  <p>works fine. But when i change it to my ip address</p>
  
  <pre><code>if __name__ == "__main__":
          app.run(host= '10.***.**')
  </code></pre>
  
  <p>throws error : </p>
  
  <blockquote>
    <p>socket.error:[errno 99] cannot assign requested address</p>
  </blockquote>
  
  <p>I checked again the ip address with a simple flask application which is running on local (i.e without docker)</p>
  
  <pre><code> if __name__ == "__main__":
              app.run(host= '10.***.**')
  </code></pre>
  
  <p>It worked fine. </p>
  
  <p>So the problem is coming only when running inside the docker. And that's because i am behind a router running NAT with internal ip address. And how do i find this internal ip address with NAT? I have already done port forwarding for flask application with port 5000. </p>
  
  <pre><code>&gt; iptables -t nat -A DOCKER -p tcp --dport 5000 -j DNAT --to-destination 172.17.0.2:5000
  &gt; iptables -t nat -A POSTROUTING -j MASQUERADE -p tcp --source 172.17.0.2 --destination 172.17.0.2 --dport https
  &gt; iptables -A DOCKER -j ACCEPT -p tcp --destination 172.17.0.2 --dport https
  </code></pre>