Java – Mac hosts do not like docker container port forwarding
This is my first attempt to use docker. I'm trying to make a @ L_ 404_ 0 @ boot web application runs in docker container I'm building the application (packaging it into a separate jar) and then adding it to the docker image (that's what I want)
You can find my sscce in boot repo on GitHub. Its readme file has all the instructions I see But basically:
>I build the web application into jar > Run docker build - t boot Which is successful > Run docker run - it - P 9200:9200 - D – name bootup bootup, and then the container seems to start, just like the evidence of docker PS output below > however, when I point the browser to http: / / localhost: 9200, I get nothing
Docker PS output:
CONTAINER ID IMAGE COMMAND CREATED a8c4ee64a1bc bootup "/bin/sh -c 'java -ja" 2 days ago STATUS PORTS NAMES Up 12 seconds 0.0.0.0:9200->9200/tcp bootup
The web application is configured to run on port 9200 instead of the Java default value of 8080 You can run/ Gradlew clean build & & & & amp& amp;& amp;& amp;& java -jar build / libs / bootup. jar.
As far as I know, no firewall blocking ports is running on my host (I verified System Preferences > > Security and privacy > > firewall is turned off on MAC 10.11.5)
Who can find where I'm wrong?
to update:
I ran curl, netstat and lsof on the host:
HOST: curl http://localhost:9200 curl: (52) Empty reply from server netstat -an | grep 9200 tcp6 0 0 ::1.9200 *.* LISTEN tcp4 0 0 *.9200 *.* LISTEN lsof -n -i4TCP:9200 | grep LISTEN com.docke 2578 myuser 19u IPv4 <someHexNumber> 0t0 TCP *:wap-wsp (LISTEN)
Then docker executes into the container and runs another netstat:
CONTAINER: netstat -an | grep 9200 bash: netstat: command not found
Update w / photos:
My browser (chrome) image points to http: / / localhost: 9200:
Http: / / localhost: 9200 source code image:
Chrome developer tools checks the picture of the page at http: / / localhost: 9200:
Picture of "network" tab in chrome developer tool:
What the hell is going on?!?!? According to the source, the browser should render my well from Dockland! Just the news According to the actual browser page, there seems to be a network error According to chrome developer tools, my application is returning a variety of HTML / CSS / JS content, which is even far away from my application (please check the source code and see it for yourself)!
Solution
To add another answer here, because I saw the content related to your GitHub repo:
Therefore, repo is an application Spring boot repo. Of the YML file
Your dockerfile is as follows:
FROM openjdk:8 RUN mkdir /opt/bootup ADD build/libs/bootup.jar /opt/bootup WORKDIR /opt/bootup EXPOSE 9200 ENTRYPOINT java -jar bootup.jar
This is to add the built jar to the image If my understanding is correct, the jar does not contain application YML, because:
>It is not part of the build (gradle only packages Src / main) It is located in the project root folder > it is not explicitly added to docker
So you can assume that your application is actually running on 8080 (the default)?
Several options to try:
>Try exposing 8080 instead of 9200 (or both) to see if you can make a difference? > The entrypoint command can attach a port – server Port = 9200 > application Add the YML file to the image (you may need to add a parameter to refer to it correctly) [add application.yml/opt/boot, after the first add command] > include application in Src / main / resources YML file so that spring boot can get it automatically
reference resources
Spring Boot reference documentation on the order of loading for external configuration