我正在使用.NET Core中的“添加Docker支持”选项,并具有以下自动生成的启动设置:
{
"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正在自动打开它创建的IP地址
https://172.20.167.220/
它会超时。
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]