0

I am running 2 spring boot applications: A client and rest-api. The client communicates to the rest-api which communicates to a mongodb database. All 3 tiers are running inside docker containers.

I launch the containers normally specifying the exposed ports in the dockerfile and mapping them to a port on the host machine such as: -p 7070:7070, where 7070 is a port exposed in the Dockerfile.

When I run the applications through the java -jar [application_name.war] command, the application works fine and they all can communicate.

However, when I run the applications in a Docker container I get connection refused error, such as when the client tries to connect to the rest-api I get a connection refused error at http://localhost:7070.

But the command docker ps shows that the containers are all running and listening on the exposed and mapped ports.

I have no clue why the containers aren't recognizing that the other containers are running and listening on their ports.

Does this have anything to do with iptables?

Any help is appreciated.

Thanks

EDIT 1: The applications when ran inside containers work fine on my machine, and they don't throw any connection refused errors. The error only happens on that particular different machine.

Kingamere
  • 9,496
  • 23
  • 71
  • 110
  • get into the container with a `docker exec -it container_id bash` and debug it like you would do on any system, for example does `netstat -an` show the expected results? – user2915097 Sep 14 '15 at 16:20
  • "only happens on that particular different machine". You're not exactly making this easy to diagnose. Why is that machine different? – Adrian Mouat Sep 14 '15 at 16:27
  • It is an ec2-instance and it doesn't work there. I also configured the AWS security group to allow connections on the ports the applications listen on. And I will try sshing into the container – Kingamere Sep 14 '15 at 16:54
  • @ user2915097, it says "netstat: command not found" when I went into the container – Kingamere Sep 14 '15 at 18:12
  • How do you reference your dependencies? If you are using `localhost:` it just can't work cause all your containers will get different addresses. Either you make all ports publicly available and reference by the hosts address or better use container linking. – daniel.eichten Sep 14 '15 at 19:25
  • The containers themselves will get different addresses, but they can still be accessed by localhost and the exposed port that is mapped to the host machine. This is according to the docker docs and which works on my local machine. However, on the ec2-isntance this doesn't. – Kingamere Sep 14 '15 at 19:49

1 Answers1

2

I used container linking to solve this problem. Make sure you add --link <name>:<alias> at run-time to the container you want linked. <name> is the name of the container you want to link to and <alias> will be the host/domain of an entry in Spring's application.properties file.

Example:

spring.data.mongodb.host=mongodb if the alias supplied at run-time is 'mongodb':

--link myContainerName:mongodb
Kingamere
  • 9,496
  • 23
  • 71
  • 110