2 Docker容器与Docker Compose之间的Http通信

问题描述:

我有两个docker容器(Windows 10主机上的linux容器),它们是从microsoft/aspnetcore基础映像构建的。当我单独启动它们时,两个容器都运行良好。我正在尝试使用Docker Compose启动两个容器(一个是使用IdentityServer的身份提供程序,另一个是受Identity Server保护的api资源)。我有以下泊坞窗,compose.yml文件:2 Docker容器与Docker Compose之间的Http通信

version: '3' 

services: 
    identityserver: 
    image: eventloom/identityserver 
    build: 
     context: ../Eventloom.Web.IdentityProvider/Eventloom.Web.IdentityProvider 
     dockerfile: DockerFile  
    ports: 
     - 8888:80 
    eventsite: 
    image: eventloom/eventsite 
    build: 
     context: ./Eventloom.Web.Eventsite 
     dockerfile: Dockerfile 
    ports: 
     - 8080:80 
    links: 
     - identityserver 
    depends_on: 
     - identityserver 
    environment: 
     IdentityServer: "http://identityserver" 

为“eventsite”容器启动类使用IdentityModel ping通的“identityserver”的发现端点。出于某种原因,即使我可以登录到eventsite容器并从身份服务器获取ping响应,启动永远也无法成功获取发现信息。还有什么我需要做的,以允许赛事通过端口80与身份服务器进行通信?

+0

你可以给错误日志? –

+1

我可以看到您在docker-compose文件中使用了depends_on和链接。你只需要使用其中的一个(他们做同样的事情)。确保您在配置文件中使用服务名称,以使不同的容器相互通信。 – sys0dm1n

+1

请勿使用链接(它们已弃用)。当您使用现代版本的docker-compose时,默认情况下容器会自动联网。例如,您可以从主机名为'identityserver'的eventsite容器中访问identityserver。将服务名称更改为所需的任何主机名。 – mkasberg

事实证明,HTTP通信工作正常,并正确使用内部DNS。问题出在我的IdentityModel.DiscoveryClient对象上,而没有配置它只允许HTTP。我不得不使用VS进行调试,因为应用程序是在容器内部开始计算出来的。谢谢。