Version of Tomcat Server: tomcat-9.0.10
Basically I have a docx file hosted in the ROOT folder of my tomcat server. If i try to get the file on my browser it works using "http://localhost:1212/Manufacturing.docx". When I try to use the file in a local build of my webapp it works. But when i try to use "http://localhost:1212/Manufacturing.docx" in my app hosted on the docker container, it fails to get the file (it seems like it cannot establish a connection). Any idea why I can server the file outside of the container but cannot inside the container?
CodePudding user response:
When you try to access localhost
from a container, it resolves to the localhost within the container and not the host.
Possible solutions:
- If you are using Docker 18.03 and are on Windows / Mac, accessing
host.docker.internal
will resolve to the 127.0.0.1 of the host machine. - Run your container using
docker run -d --network=host your-image:tag
. This way your container will share the networking namespace with your host andlocalhost
inside the container will be the same aslocalhost
on the host.
Also see: From inside of a Docker container, how do I connect to the localhost of the machine? and What is linux equivalent of "host.docker.internal"