1

My question can be naive, but I'm new to development and docker, and couldn't figure out the solution. I have an image of GraphDB-Free which I can run as a docker container, and it runs on localhost:7200. I can access it in chrome also.

Now I have another module ModelService which is spring boot application to read and write data to the GraphDB. I created an image of the module and ran it as a docker container, but everytime it gives me a Connection Refused error like the following:

Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:7200 [localhost/127.0.0.1] failed: Connection refused (Connection refused).

This problem is only If I run the module ModelService by using a docker container. If I run it as a simple java application from intelliJ, it runs fine and gets connected with GraphDB instance that I ran inside a container.

This ModelService module starts a springboot application and has a application.properties file that specifies it to connect with GraphDB using register.graphDbUrl=http://localhost:7200 and register.repositoryId=SYSTEM.

I believe I'm missing something with Docker containers. I don't want to use Docker-Compose, and point is to run both containers as stand alone containers. I have tried --link while running docker run but it doesn't helps.

I run the GDB instance using docker run -p 7200:7200 graphDB-image, and ModelService using docker run -p 9001:8080 modelService-image. I do wait before the GraphDB is completey up and running, and then I run other container.

Can somebody help in this. I've struggling with it for 2 days.

Raees
  • 21
  • 1
  • 3
  • Possible duplicate of [how to link container in docker?](https://stackoverflow.com/questions/41768157/how-to-link-container-in-docker) – Teemu Risikko Jul 12 '18 at 12:04
  • That is not what I'm looking for unfortunately. :( My ModelService application is a springboot application which while launching the Tomcat, tries to connect with localhost:7200, and crashes there. – Raees Jul 12 '18 at 12:25
  • 3
    So you are trying to connect from one container to another? If you use localhost inside a container, it does not point to the localhost of the *host* machine, but to the localhost of the container, which is not the same thing. – Teemu Risikko Jul 12 '18 at 12:27
  • https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach this might also solve your problem (using host network). – Teemu Risikko Jul 12 '18 at 12:53
  • @TeemuRisikko This is the problem yes, to access localhost from inside the other container (other container will fail to run, which is a springboot app, if localhost is nor reachable). I have seen the post you have mentioned, but couldn't get the solution for my case. It might be that I'm a bit new to these concepts and need a bit more simple clarification. Hopefully someone can help, thinking that I'm a complete beginner. – Raees Jul 13 '18 at 07:15

0 Answers0