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 requests addressed to the user, and 9100 for administrative tasks, such as health checks. When I start the docker instance and try to access port 9000, I get the following error:
curl: (56) Recv failure: Connection reset by peer
After a lot of experimentation (via curl), I confirmed several different configurations that the application works fine in the container, but when I try to map the ports to the host, it does not connect. I tried to run it with the following commands. None of them allow me to access ports from the host.
docker run -P=true my-app docker run -p 9000:9000 my-app
Workaround
The only approach that works uses the parameter - net host , but this does not allow me to run more than one container on this host.
docker run -d --net=host my-app
Port Experiments and Exposure
I used different versions of Dockerfile, demonstrating different ports, such as 9000 and 9100 or only 9000. None of this helped. Here is my latest version:
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
Work Hello World
To make sure that I can run the Spring boot application, I tried Simplest-Spring-Boot-MVC-HelloWorld and it worked fine.
Netstat Results
I used netstat to scan ports from the host and from the container:
From host
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
Out of container
root@80cf20c0c1fa :/opt/app
The container uses Ubuntu. The hosts I played are Centos and Ubuntu.
This SO question seems similar, but has very few details and answers, so I thought I would try to document my script a bit more.