title: Docker port isn't accessible from host
body: <p>I have a new Spring Boot application that I just finished and am trying to deploy it to Docker. Inside the container the application works fine. It uses ports 9000 for user facing requests and 9100 for administrative tasks like health checks. When I start a docker instance and try to access port 9000 I get the following error:</p>
  
  <pre><code>curl: (56) Recv failure: Connection reset by peer
  </code></pre>
  
  <p>After a lot of experimentation (via curl), I confirmed in with several different configurations that the application functions fine inside the container, but when I try to map ports to the host it doesn't connect. I've tried starting it with the following commands. None of them allow me to access the ports from the host.</p>
  
  <pre><code>docker run -P=true my-app
  docker run -p 9000:9000 my-app
  </code></pre>
  
  <h1>The workaround</h1>
  
  <p>The only approach that <a href="https://stackoverflow.com/questions/26543787/docker-mule-server-curl-56-recv-failure-connection-reset-by-peer">works</a> is using the <a href="https://docs.docker.com/articles/networking/#container-networking" rel="nofollow noreferrer">--net host option</a>, but this doesn't allow me to run more than one container on that host.</p>
  
  <pre><code>docker run -d --net=host my-app
  </code></pre>
  
  <h1>Experiments with ports and expose</h1>
  
  <p>I've used various versions of the Dockerfile exposing different ports such as 9000 and 9100 or just 9000. None of that helped. Here's my latest version:</p>
  
  <pre><code>FROM ubuntu
  MAINTAINER redacted
  
  RUN apt-get update
  RUN apt-get install openjdk-7-jre-headless -y
  RUN mkdir -p /opt/app
  
  WORKDIR /opt/app
  
  ADD ./target/oauth-authentication-1.0.0.jar /opt/app/service.jar
  ADD config.properties /opt/app/config.properties
  
  EXPOSE 9000
  ENTRYPOINT java -Dext.properties.dir=/opt/app -jar /opt/app/service.jar
  </code></pre>
  
  <h1>Hello World works</h1>
  
  <p>To make sure I can run a Spring Boot application, I tried <a href="https://github.com/Barlog-M/Simplest-Spring-Boot-MVC-HelloWorld" rel="nofollow noreferrer">Simplest-Spring-Boot-MVC-HelloWorld</a> and it worked fine.</p>
  
  <h1>Netstat Results</h1>
  
  <p>I've used netstat to do port scans from the host and from the container:</p>
  
  <h3>From the host</h3>
  
  <pre><code>root@my-docker-host:~# nmap 172.17.0.71 -p9000-9200
  
  Starting Nmap 6.40 ( http://nmap.org ) at 2014-11-14 19:19 UTC Nmap
  scan report for my-docker-host (172.17.0.71)
  Host is up (0.0000090s latency).
  Not shown: 200 closed ports
  PORT     STATE SERVICE
  9100/tcp open  jetdirect
  MAC Address: F2:1A:ED:F4:07:7A (Unknown)
  
  Nmap done: 1 IP address (1 host up) scanned in 1.48 seconds
  </code></pre>
  
  <h3>From the container</h3>
  
  <pre><code>root@80cf20c0c1fa:/opt/app# nmap 127.0.0.1 -p9000-9200
  
  Starting Nmap 6.40 ( http://nmap.org ) at 2014-11-14 19:20 UTC
  Nmap scan report for localhost (127.0.0.1)
  Host is up (0.0000070s latency).
  Not shown: 199 closed ports
  PORT     STATE SERVICE
  9000/tcp open  cslistener
  9100/tcp open  jetdirect
  
  Nmap done: 1 IP address (1 host up) scanned in 2.25 seconds
  </code></pre>
  
  <p>The container is using Ubuntu
  The hosts I've replicated this are Centos and Ubuntu.</p>
  
  <p><a href="https://stackoverflow.com/questions/26537652/docker-port-mapping-isnt-working-as-expected-with-osgi-servlet">This SO question</a> seems similar but had very few details and no answers, so I thought I'd try to document my scenario a bit more.</p>