title: Bind docker container loopback to the host loopback
body: <p>I pull a docker image (will use python 3 as an example)</p>
  
  <pre><code>docker pull python:3.6
  </code></pre>
  
  <p>Then I launch a docker container</p>
  
  <pre><code>docker run -it -p 127.0.0.1:8000:8000 python:3.6 bash
  </code></pre>
  
  <p>(note that here 127.0.0.1 in 127.0.0.1:8000:8000 allows to specify the destination, host IP but not the source)</p>
  
  <p>So if I launch a server inside the container at 0.0.0.0:</p>
  
  <pre><code>python -m http.server 8000 --bind 0.0.0.0
  </code></pre>
  
  <p>then I can access the container's server from the host machine without any problem by going to <a href="http://127.0.0.1:8000" rel="nofollow noreferrer">http://127.0.0.1:8000</a> at the host machine</p>
  
  <p>However if my docker server binds to 127.0.0.1 instead of 0.0.0.0:</p>
  
  <pre><code>python -m http.server 8000 --bind 127.0.0.1
  </code></pre>
  
  <p>then accessing <a href="http://127.0.0.1:8000" rel="nofollow noreferrer">http://127.0.0.1:8000</a> from the host does not work.</p>
  
  <p>What's the proper way of binding the container's loopback 127.0.0.1 to the host loopback?</p>