[英]Connecting to localhost from Docker (Java Application using localstack for mocking AWS)
I am using localstack to mock AWS resources locally.我正在使用 localstack 在本地模拟 AWS 资源。 This works fine when I run my application from the IDE.
当我从 IDE 运行我的应用程序时,这工作正常。 I have a dockerfile which contains the following (1338 is the port this app would run on)
我有一个 dockerfile 包含以下内容(1338 是此应用程序将运行的端口)
ADD target/myapp-0.0.1-SNAPSHOT.jar app.jar
and I have a script to run which is我有一个要运行的脚本
#!/bin/bash
set -e # Stop on errors
mvn clean package
docker build -t myapp .
docker run -it --name myapp -p 1338:1338 --rm myapp:latest
So when I run I get the error所以当我运行时,我得到了错误
Unexpected error occurred in scheduled task
com.amazonaws.SdkClientException: Unable to execute HTTP request: Connect to localhost:4575 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
I suppose you're running localstack on your host OS, that's why the myapp
unable to reach it.我想您正在主机操作系统上运行 localstack,这就是
myapp
无法访问它的原因。 To solve your issue, you need adjust your docker run
instruction by adding parameter --network host
.要解决您的问题,您需要通过添加参数
--network host
来调整您的docker run
指令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.