title: Docker port conflict on Ubuntu
body: <ul>
  <li><p>I am using Ubuntu and trying to config remote debugging with Xdebug (debugger for PHP) to work on a Docker container.</p>
  
  <pre><code>trungdq88@ubuntu:~/# ifconfig
  docker0   Link encap:Ethernet  HWaddr 02:42:7b:c2:ec:97  
            inet addr:172.17.0.1  Bcast:0.0.0.0  Mask:255.255.0.0
            inet6 addr: fe80::42:7bff:fec2:ec97/64 Scope:Link
            UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
            RX packets:8923 errors:0 dropped:0 overruns:0 frame:0
            TX packets:13333 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:0 
            RX bytes:5099353 (5.0 MB)  TX bytes:16082560 (16.0 MB)
  
  eth0      Link encap:Ethernet  HWaddr b8:ca:3a:d3:4f:03  
            UP BROADCAST MULTICAST  MTU:1500  Metric:1
            RX packets:0 errors:0 dropped:0 overruns:0 frame:0
            TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:1000 
            RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
  </code></pre></li>
  <li><p>My container <strong>exposes port 9000</strong> (Xdebug's working port).</p>
  
  <pre><code>EXPOSE 80 443 9000
  </code></pre></li>
  <li><p>Since docker machine in Ubuntu <strong>is the same as the real machine</strong>, the <code>docker-proxy</code> process takes the 9000 port</p>
  
  <pre><code>trungdq88@ubuntu:~/# sudo netstat -tulpn | grep :9000
  tcp6    0    0 :::9000    :::*     LISTEN      10391/docker-proxy
  </code></pre></li>
  <li><p>My IDE (Sublime Text) can't start the debug session because it needs to listen on port 9000 as well.</p>
  
  <pre><code>trungdq88@ubuntu:~/# echo "Assume that this is my IDE" | nc -l -p 9000 
  nc: Address already in use
  </code></pre></li>
  <li><p>I tried another port:</p>
  
  <p>In Ubuntu:</p>
  
  <pre><code>trungdq88@ubuntu:~/# echo "Hello" | nc -l -p 12345
  </code></pre>
  
  <p>Inside Docker container:</p>
  
  <pre><code>root@919737061a1d:/src# telnet 172.17.0.1 12345
  Trying 172.17.0.1...
  Connected to 172.17.0.1.
  Escape character is '^]'.
  Hello
  Connection closed by foreign host.
  </code></pre>
  
  <p>(It works on port 12345)</p></li>
  <li><p>My <code>docker-compose.yml</code>:</p>
  
  <pre><code>web:
    build: .
    ports:
      - "80:80"
      - "443:443"
      - "9000:9000"
  </code></pre></li>
  </ul>
  
  <p><code>Dockerfile</code> sets entry point to a <code>sh</code> script which run the services (php-fpm, nginx...). I use <code>docker-compose up</code> to run the container.</p>
  
  <p><strong>My questions are:</strong></p>
  
  <ul>
  <li>Is it necessary to expose ports when using Docker in Ubuntu?</li>
  <li>How can I get my IDE debug feature to work if <code>docker-proxy</code> keep listening on port 9000?</li>
  <li>I didn't expose port 12345 in my container but why the last example (netcat and telnet) still works?</li>
  </ul>