在不同的Docker容器中运行的Spring Boot应用拒绝连接 [英] Connection refused by Spring boot app running in different docker container
问题描述
我在同一主机上的3个容器中运行了三个应用程序。
I have three apps running in 3 containers on the same host.
CONTAINER ID IMAGE COMMAND PORTS
3f938111c1bf registration "java -jar registration.jar" 0.0.0.0:8030->8030/tcp
cb9c4782194e security "java -jar security.jar" 0.0.0.0:8020->8020/tcp
60005507a246 main "java -jar main.jar" 0.0.0.0:8000->8000/tcp
我能够从主目录访问安全应用程序的端点使用Ajax请求的应用程序。
I am able to access an endpoint of the security app from main app using an Ajax request.
注册应用程序使用RestTemplate对象从Java方法中调用安全应用程序的端点。该调用被安全应用程序拒绝,如下所示。
The registration app calls an endpoint of security app from a java method using a RestTemplate object. This call is refused by the security app as follows.
I/O error on POST request for "http://localhost:8020/security/register": Connect to localhost:8020 [localhost/127.0.0.1] failed: Connection refused (Connection refused); nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8020 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
我无法识别问题。 请注意,当我通过eclipse在本地运行这些应用程序时,此调用工作正常。
我对Docker来说很陌生。我有可能遗漏某些东西吗?任何线索都将有所帮助。
I am very new to the dockers. Is there a possibility that I am missing out something? Any leads would be helpful.
非常感谢!
推荐答案
使用Docker容器时/ images,因此您需要在其上设置配置。因此,您必须将localhost更改为您的容器名称。例如:
When you work with docker containers/images so you need to set your configurations on them. So you must change localhost to your container name. For example:
http://localhost:8020/security/register
http://authentication:8020/security/register
这篇关于在不同的Docker容器中运行的Spring Boot应用拒绝连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!