Docker port not available at host

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# 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 

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.

+5
source share
2 answers

I had a similar problem in which specifying the host IP address as "127.0.0.1" incorrectly redirected the port to the host.

Setting the IP address of the web server to "0.0.0.0" fixes the problem.

for example - for my Node application - < works

 app.listen(3000, '127.0.0.1') 

Where do the following work :

 app.listen(3000, '0.0.0.0') 

Which, I think, means that docker by default shows 0.0.0.0:containerPort -> local port

+9
source

You need to start using docker run -P so that the ports are automatically mapped to the same values ​​as in the Docker file. See http://docs.docker.com/reference/run/#expose-incoming-ports

+3
source

Source: https://habr.com/ru/post/1206905/


All Articles