[英]Docker containers unable to connect to each other
我正在使用docker compose構建微服務解決方案以在本地運行。 我正在使用.netcore提供服務。 當我使用Visual Studio運行項目時,所有連接都可以正常運行,但是當我在Docker中運行時,我可以從外部連接到服務,但是服務無法相互連接。當我在Docker中進行檢查時,一切看起來都很好並且所有容器都處於打開狀態同一網絡。 我假設這是我所缺少的一些小設置或配置,但找不到任何存在相同問題的人。
這是docker-compose代碼
docker-compose.yml
version: '3'
services:
underrule.frontend:
image: underrule.frontend
build:
context: ./UnderRule.FrontEnd
dockerfile: Dockerfile
underrule.apigateway:
image: underrule.apigateway
build:
context: ./UnderRule.ApiGateway
dockerfile: Dockerfile
underrule.authentication:
image: underrule.authentication
build:
context: ./UnderRule.Authentication
dockerfile: Dockerfile
underrule.playerservice:
image: underrule.playerservice
build:
context: ./UnderRule.PlayerService
dockerfile: Dockerfile
underrule.registrationservice:
image: underrule.registrationservice
build:
context: ./UnderRule.RegistrationService
dockerfile: Dockerfile
underrule.worldservice:
image: underrule.worldservice
build:
context: ./UnderRule.WorldService
dockerfile: Dockerfile
docker-compose.override.yml
version: '3'
services:
underrule.frontend:
environment:
- ASPNETCORE_ENVIRONMENT=Development
ports:
- "5000:80"
underrule.apigateway:
environment:
- ASPNETCORE_ENVIRONMENT=Development
ports:
- "9000:80"
underrule.authentication:
environment:
- ASPNETCORE_ENVIRONMENT=Development
ports:
- "5001:80"
underrule.playerservice:
environment:
- ASPNETCORE_ENVIRONMENT=Development
ports:
- "5002:80"
underrule.registrationservice:
environment:
- ASPNETCORE_ENVIRONMENT=Development
ports:
- "5004:80"
underrule.worldservice:
environment:
- ASPNETCORE_ENVIRONMENT=Development
ports:
- "5003:80"
all dockerfiles are basically the same
FROM microsoft/aspnetcore:2.0
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "UnderRule.ApiGateway.dll"]
有任何想法嗎? 我嘗試在沒有太多運氣的情況下弄亂端口。
我正在內部使用HttpClient與類似http:// localhost的路徑進行連接:{port}
非常感謝您的幫助,如果您需要更多信息,請告訴我。
在容器內,localhost指向容器本身,而不是橋接網絡。
在使用docker-compose時,您應指向docker-compose.yml文件中定義的容器名稱(例如, underrule.worldservice- > http://underrule.worldservice:port )。
另一種方法是指向docker bridge網絡ip。 在Linux上,此IP默認為172.17.0.1。 在Windows上,這取決於您運行的docker版本,您應該檢查配置( ipconfig
)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.