我正在使用.NET Core中的add docker支持选项,我有以下自动生成的launchSettings:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:49800",
      "sslPort": 44327
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "WebApplication1": {
      "commandName": "Project",
      "launchBrowser": true,
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

以下是 docker-compose.override.yml

version: '3.4'

services:
  webapplication1:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=https://+:443;http://+:80
      - ASPNETCORE_HTTPS_PORT=44327
    ports:
      - "49800:80"
      - "44327:443"
    volumes:
      - ${APPDATA}/ASP.NET/Https:C:\Users\ContainerUser\AppData\Roaming\ASP.NET\Https:ro
      - ${APPDATA}/Microsoft/UserSecrets:C:\Users\ContainerUser\AppData\Roaming\Microsoft\UserSecrets:ro
networks:
  default:
    external:
      name: nat

Docker会自动打开它在https://172.20.167.220/创建的IP地址,并且超时 .

dockerfile的顶部如下所示:

FROM microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-sac2016 AS base
WORKDIR /app
EXPOSE 49800
EXPOSE 44327
EXPOSE 443 #I added this line as an experiment

我不确定实际使用的是什么IP地址和端口,因为launchSettings.json没有“docker”配置文件,但启动应用程序的唯一方法是从调试播放按钮中选择Docker . 这个应用程序是由docker mvc核心模板创建的 . 这在Program.cs中调用CreateDefaultBuilder,因此Kestrel在localhost:5000/50001上运行,我假设它由默认构建器创建的iisintegration映射到端口49800和44327,然后应该通过docker将其映射到端口80和443 . 然后打开的标准IP地址 . 我应该在docker中打开防火墙端口吗?

我怀疑我可能在这里做错了,我在 Program.cs 中对安全证书进行了硬编码:

public static IWebHostBuilder CreateWebHostBuilder(string[] args ) =>
            WebHost.CreateDefaultBuilder(args).UseKestrel(options=>
            {
                options.Listen(IPAddress.Loopback, 5000);
                options.Listen(IPAddress.Loopback, 5001, listenOptions =>
                {
                    listenOptions.UseHttps(@"C:\Users\ContainerUser\AppData\Roaming\ASP.NET\Https\WebApplication1.pfx", "bede5cf6-6b63-427a-8576-d3a137f51070");
                });
            }

我连接到容器并且docker设置中的某些内容不正确,因为在运行netstat时没有正在侦听端口443,并且中间iis似乎没有在49800/44327上运行 . :

C:\app>netstat -a -b -n -o

Active Connections

  Proto  Local Address          Foreign Address        State           PID
  TCP    0.0.0.0:135            0.0.0.0:0              LISTENING       4960
 [svchost.exe]
  TCP    0.0.0.0:4022           0.0.0.0:0              LISTENING       9804
 [msvsmon.exe]
  TCP    0.0.0.0:5985           0.0.0.0:0              LISTENING       4
 Can not obtain ownership information
  TCP    0.0.0.0:47001          0.0.0.0:0              LISTENING       4
 Can not obtain ownership information
  TCP    0.0.0.0:49152          0.0.0.0:0              LISTENING       9192
 Can not obtain ownership information
  TCP    0.0.0.0:49153          0.0.0.0:0              LISTENING       11208
 [svchost.exe]
  TCP    0.0.0.0:49154          0.0.0.0:0              LISTENING       10080
 Can not obtain ownership information
  TCP    0.0.0.0:49155          0.0.0.0:0              LISTENING       3884
 [lsass.exe]
  TCP    127.0.0.1:5000         0.0.0.0:0              LISTENING       8892
 [dotnet.exe]
  TCP    127.0.0.1:5001         0.0.0.0:0              LISTENING       8892
 [dotnet.exe]
  TCP    172.20.170.223:4022    172.20.160.1:54632     ESTABLISHED     5472
 [msvsmon.exe]
  TCP    172.20.170.223:49421   64.4.54.254:443        TIME_WAIT       0
  TCP    [::]:135               [::]:0                 LISTENING       4960
 [svchost.exe]
  TCP    [::]:4022              [::]:0                 LISTENING       9804
 [msvsmon.exe]
  TCP    [::]:5985              [::]:0                 LISTENING       4
 Can not obtain ownership information
  TCP    [::]:47001             [::]:0                 LISTENING       4
 Can not obtain ownership information
  TCP    [::]:49152             [::]:0                 LISTENING       9192
 Can not obtain ownership information
  TCP    [::]:49153             [::]:0                 LISTENING       11208
 [svchost.exe]
  TCP    [::]:49154             [::]:0                 LISTENING       10080
 Can not obtain ownership information
  TCP    [::]:49155             [::]:0                 LISTENING       3884
 [lsass.exe]
  UDP    0.0.0.0:5353           *:*                                    10676
 [svchost.exe]
  UDP    0.0.0.0:5355           *:*                                    10676
 [svchost.exe]
  UDP    [::]:5353              *:*                                    10676
 [svchost.exe]
  UDP    [::]:5355              *:*                                    10676
 [svchost.exe]