0

How to access a webservice outside of the docker image. Any hint or suggestion would be greatly appreciated it!!

I have an spring boot application that calls a localhost gremlin server and a localhost mongo db server.

For my spring boot application, i build the docker image based on plugin:

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-maven-plugin</artifactId>

            <configuration>

                <image>

                    <name>jadeite1000/${project.artifactId}</name>

                </image>

            </configuration>

        </plugin>

But when I run the webservice inside the docker image it doesn't seem to be able to access the "localhost" gremlin server outside of the docker image.

How can I resolve this problem.

jadeite1000
  • 621
  • 2
  • 11
  • 27
  • When you say "localhost", where is it actually? (Each Docker container individually believes it's `localhost`; the host system believes it's `localhost`, separately from any of the containers; if you have a second system, that's a different `localhost`; and so on.) – David Maze Feb 07 '22 at 18:55
  • the quick and dirty hack is to use `--network host`. If those things run on the host system. If you run them also in container, you should join the container on a network and use the container name as hostname. – The Fool Feb 07 '22 at 18:58
  • On my laptop I am running the gremlin server on "localhost" and the mongodb server on localhost. Also, On the laptop I have a docker container that contains a spring boot web service. This spring boot webservice is trying to accessing a "localhost" gremlin and mongdb server inside container. I can't access because the container cannot access the mongodb and gremlin server outside the container. My question is that to enable the spring boot inside the container to be able to access the mongodb and gremlin server outside of the container. – jadeite1000 Feb 07 '22 at 19:20
  • If you're using the Docker Desktop application, there's a special host name `host.docker.internal` that reaches the host system; the linked question describes other environments as well. I do not recommend using `--net host` to disable Docker networking. – David Maze Feb 07 '22 at 19:29
  • Hi David, thank you so much for answering my question. Based on this url: https://docs.docker.com/desktop/windows/networking/ I should be running something like ? docker run -p 80:80 -d nginx – jadeite1000 Feb 07 '22 at 19:52

0 Answers0