我试图将一个带有Angular的Asp.Net Core App放在一个docker容器中。
我构建了这个例子 https:/github.comcschulcAspNetCoreAngularDocker。
我运行。
dotnet publish -c Release -o ./publish
在这之后,我试着从发布目录中运行应用程序,并使用
dotnet DockerExample.dll
并且运行正常。
现在我使用DockerFile来构建一个DockerImage。
Docker文件
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
EXPOSE 80
EXPOSE 443
WORKDIR /app
COPY ["/publish", "/app"]
ENTRYPOINT ["dotnet", "DockerExample.dll"]
命令。
docker build -t dockerexample .
并运行容器与
docker run dockerexample
输出是这样的
warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
No XML encryptor configured. Key {6fda42c9-4247-47ec-b7b9-0b10d68b002e} may be persisted to storage in unencrypted form.
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://[::]:80
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /app
但当我去 http:/localhost 我得到了ERR_CONNECTION_REFUSED的信息。
我也试过
docker run -p 80:80 -p 443:443 dockerexample
但也得到了ERR_CONNECTION_REFUSED。
谁能帮帮我,好吗?
解决方案:
因此,我通过将Program.CreateHostBuilder的内容修改为以下内容来解决这个问题
var config = new ConfigurationBuilder()
.Build();
return WebHost.CreateDefaultBuilder(args)
.UseConfiguration(config)
.UseUrls("http://*:5000")
.UseStartup<Startup>();
并移除Line
app.UseHttpsRedirection();
来自Startp.Configure
本文来自投稿,不代表运维实战侠立场,如若转载,请注明出处:https://www.shizhanxia.com/1717.html