通过https连接不同Docker容器中的应用

时间:2019-11-26 14:58:33

标签: docker ssl asp.net-core https docker-compose

连接在单独的Docker容器中运行的两个ASP.NET Core应用程序时遇到一些问题。 这是我使用的yml文件的示例:

version: '3.4'

services:
  webapi:
    image: ${DOCKER_REGISTRY-}webapi
    build:
      context: .
      dockerfile: apps/webapi/Dockerfile
    ports:
      - 8186:80
      - 8185:443

  consumingService:
    image: ${DOCKER_REGISTRY-}consumingService
    build:
      context: .
      dockerfile: apps/consumingService/Dockerfile
    environment:
      - WebApiUrl=https://webapi/api/someMethod
    depends_on:
      - webapi
    ports:
      - 8180:80

Webapi配置为使用https。从我的主机https://localhost:8185访问webapi可以正常工作。 但是在consumingService中执行以下代码最终会导致异常:

using (var client = new HttpClient())
{
    try
    {
        var content = new StringContent(JsonConvert.SerializeObject(configs), Encoding.UTF8, "application/json");
        var result = await client.PostAsync(serviceUrl, content);
    }
    catch (Exception e)
    {
        Debug.WriteLine(e);
    }
}
System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
 ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

关于如何解决此问题的任何想法? 提前谢谢!

0 个答案:

没有答案