gpt4 book ai didi

docker - ASP.NET Core 2.0 在 Kubernetes 中启动 Kestrel 时出错

转载 作者:IT老高 更新时间:2023-10-28 21:40:36 30 4
gpt4 key购买 nike

创建了一个新的 ASP.NET Core 2.0 项目,它在本地运行良好。然后在本地的 Docker 容器中运行它后,它也可以正常工作。但是当我尝试在 Kubernetes pod 中使用 Docker 镜像时,它会运行几分钟,然后给我这个:

    Unhandled Exception: System.InvalidOperationException: A path base can 
only be configured using IApplicationBuilder.UsePathBase().
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.
<BindAddressAsync>d__7.MoveNext()

这是我的Program.cs:

public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}

Startup.cs:

public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
HotModuleReplacement = true,
ReactHotModuleReplacement = true
});
}
else
{
app.UseExceptionHandler("/Home/Error");
}

app.UseStaticFiles();

app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");

routes.MapSpaFallbackRoute(
name: "spa-fallback",
defaults: new { controller = "Home", action = "Index" });
});
}
}

最佳答案

发生此错误时,我们使用 FROM microsoft/aspnetcore-build:1.1 基础镜像作为构建和运行时。在我们遇到错误时,我们只是尝试升级到 FROM microsoft/aspnetcore-build:2.0。我不确定这张图片的具体问题是什么,但 Kubernetes 不喜欢它。

稍后,我们将 dockerfile 切换为多阶段;使用 FROM microsoft/aspnetcore-build:1.1 构建并使用 FROM microsoft/dotnet:1.1-runtime 运行,当我们将其升级到相应的 2.0 版本时,我们没有不会再遇到这个错误了。

关于docker - ASP.NET Core 2.0 在 Kubernetes 中启动 Kestrel 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46351129/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com