我正在构建一个使用docker compose在本地运行的微服务解决方案。我正在使用.netcore提供服务。当我使用visual studio运行项目时,一切都很正常,但是当我在docker中运行时,我可以从外部连接到服务,但是服务无法连接到我在docker中检查的每个other.When,所有的容器看起来都正常,并且所有容器都在同一个网络上。我假设这是一些小的设置或配置,我错过了,但还没有能够找到任何人有相同的问题。
这是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"]有什么想法吗?我试过弄乱端口,但没有太多运气。
我正在使用类似于http://localhost:{ HttpClient }的路径在内部连接
非常感谢您的帮助,如果您需要更多信息,请让我知道。
发布于 2018-02-10 14:32:33
在容器中,localhost指向容器本身,而不是桥接网络。
在使用docker-compose时,应指向在docker-compose.yml文件中定义的容器名称(例如underrule.worldservice -> http://underrule.worldservice:port)。
另一种方式是指向坞站网桥网络ip。在linux上,此IP默认为172.17.0.1。在windows上,这取决于您正在运行的docker的版本,您应该检查您的配置(ipconfig)。
https://stackoverflow.com/questions/48715395
复制相似问题