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.
答案 0 :(得分:2)
我使用容器链接来解决这个问题。确保在运行时将--link <name>:<alias>
添加到要链接的容器中。 <name>
是要链接到的容器的名称,<alias>
将是Spring的application.properties文件中条目的主机/域。
示例:
spring.data.mongodb.host=mongodb
如果在运行时提供的别名是&#39; mongodb&#39;:
--link myContainerName:mongodb