title: Binding a port to a host interface using the REST API
body: <p>The documentation for the commandline interface says the following:</p>
  
  <blockquote>
    <p>To bind a port of the container to a specific interface of the host
    system, use the -p parameter of the docker run command:</p>
    
    <p>General syntax </p>
    
    <p><code>docker run -p [([&lt;host_interface&gt;:[host_port]])|(&lt;host_port&gt;):]&lt;container_port&gt;[/udp] &lt;image&gt;</code></p>
    
    <p> When no host interface is provided, the port is bound to
    all available interfaces of the host machine (aka INADDR_ANY, or
    0.0.0.0).When no host port is provided, one is dynamically allocated. The possible combinations of options for TCP port are the following</p>
  </blockquote>
  
  <p>So I was wondering how I do the same but with the REST API?</p>
  
  <p>With <code>POST /container/create</code> I tried:</p>
  
  <ul>
  <li><code>"PortSpecs": ["5432:5432"]</code> this seems to expose the port but not bind it to the host interface.</li>
  <li><code>"PortSpecs": ["5432"]</code> gives me the same result as the previous one. </li>
  <li><code>"PortSpecs": ["0.0.0.0:5432:5432"]</code> this returns the error <code>Invalid hostPort: 0.0.0.0</code> which makes sense.</li>
  </ul>
  
  <p>When I do <code>sudo docker ps</code> the container shows <code>5432/tcp</code> which should be <code>0.0.0.0:5432/tcp</code>.</p>
  
  <p>Inspecting the container gives me the following:</p>
  
  <pre><code>"NetworkSettings": {
      "IPAddress": "172.17.0.25",
      "IPPrefixLen": 16,
      "Gateway": "172.17.42.1",
      "Bridge": "docker0",
      "PortMapping": null,
      "Ports": {
          "5432/tcp": null
      }
  }
  </code></pre>
  
  <p>Full inspect can be found <a href="https://gist.github.com/Enome/746f1bf1cbb2d15f9733" rel="noreferrer">here</a>.</p>