Created a new ASP.NET Core 2.0 project and it runs fine locally. Then after running it in a Docker container locally it also works fine. But when I try to use the Docker image in a Kubernetes pod, it will run for a couple minutes and then give me this:
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()
Here is my 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" });
});
}
}
It require https certificate to run. There are two ways to fix the issue . 2- Switching back to Kestrel and changing the port number in the applicationUrl setting in the launchSettings. json file fixed the issue.
Kestrel is a cross-platform web server for ASP.NET Core. Kestrel is the web server that's included by default in ASP.NET Core project templates. Kestrel supports the following scenarios: HTTPS.
When this error was happening, we were using the FROM microsoft/aspnetcore-build:1.1
base image as our build and runtime. At the time we were encountering the error, we had simply tried to upgrade to FROM microsoft/aspnetcore-build:2.0
. I'm not certain what specifically the issue with this image was, but Kubernetes didn't like it.
At a later date, we switched the dockerfile to multistage; building with FROM microsoft/aspnetcore-build:1.1
and running with FROM microsoft/dotnet:1.1-runtime
, and when we upgraded that to the corresponding 2.0 versions, we didn't encounter this error again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With