简体   繁体   English

将运行在bridge网络上的Docker Container连接到Localhost

[英]Connecting Docker Container running on bridge network to Localhost

I am running localstack (AWS mock service) locally as a docker container.我在本地运行 localstack(AWS 模拟服务)作为 docker 容器。 I have another application which tries to connect to it but is getting connection refused error both are java projects.我有另一个应用程序尝试连接到它,但出现连接被拒绝错误都是 java 项目。 The network I am trying to use is called serview so I run localstack with the following我尝试使用的网络称为 serview 所以我使用以下命令运行 localstack

docker run --net=serview -d -p 4566-4597:4566-4597 --name=localstack -it localstack/localstack:latest

Then I run my other application that wants too access it like this然后我运行我的其他应用程序也想像这样访问它

docker run --net=serview  -it --name sample-publisher -p 1338:1338 --rm sample-publisher:latest

The error I am getting is this我得到的错误是这个

com.amazonaws.SdkClientException: Unable to execute HTTP request: Connect to localhost:4575 [localhost/127.0.0.1] failed: Connection refused (Connection refused)

Running with net=host will work fine but I want to run on the serview network is this possible?使用 net=host 运行可以正常工作,但我想在 serview 网络上运行,这可能吗?

When containers are connected to a common network you should use container names to connect to each other.当容器连接到公共网络时,您应该使用容器名称来相互连接。 Container name is a DNS name that will be resolved to container IP over common network.容器名称是 DNS 名称,将通过公共网络解析为容器 IP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM