I've set up a java application which acts as a web server and handles http requests. I've tested that it works outside the container (which it does), but when in the container my requests don't seem to get to it.
The server listens on port 3971, and the Dockerfile looks like this:
FROM java:8
ADD VaultServer /
EXPOSE 3971
EXPOSE 3972
ENTRYPOINT ["java", "-jar", "VaultServer.jar"]
Calling to the root address should return something (normally I'd send a GET to http://localhost:3971/).
I've tried replacing 'localhost' with the the ip address of docker-machine, and also with the ip address I get when inspecting the running container for my server, but neither seem to respond. When I call to the ip address of docker-machine, I get ERR_CONNECTION_REFUSED. Is there something else I need to enable?
Connecting to the Host NetworkDocker provides a host network which lets containers share your host's networking stack. This approach means localhost inside a container resolves to the physical host, instead of the container itself. Now your container can reference localhost or 127.0. 0.1 directly.
you are doing EXPOSE 3972 which exposes the port to other linked containers but NOT to the host machine
To expose the port to the host machine you do ...
docker run -p 3972:3972 ....... etc
you can also do ...
docker run -P
which exposes all ports exposed by EXPOSE to the host (this is not the default - you must use the -P flag here)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With