在不同的 docker 容器中运行的 Spring boot 应用程序拒绝连接

Abh*_*ash 4 rest docker spring-boot

我有三个应用程序在同一主机上的 3 个容器中运行。

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   
Run Code Online (Sandbox Code Playgroud)

我可以使用 Ajax 请求从主应用程序访问安全应用程序的端点。

注册应用程序使用 RestTemplate 对象从 java 方法调用安全应用程序的端点。安全应用程序拒绝此调用,如下所示。

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)
Run Code Online (Sandbox Code Playgroud)

我无法确定问题所在。请注意,当我通过 eclipse 在本地运行这些应用程序时,此调用工作得非常正常。

我对码头工人来说很陌生。我是否有可能错过了什么?任何线索都会有帮助。

多谢!

Jon*_*ohx 5

当您使用 docker 容器/镜像时,您需要对其进行配置。因此,您必须将 localhost 更改为您的容器名称。例如:

 http://localhost:8020/security/register

 http://authentication:8020/security/register
Run Code Online (Sandbox Code Playgroud)