AspNetCore.Docs
AspNetCore.Docs copied to clipboard
Host shuts down immediately
I'm trying to run a long running background task in a console application inside docker container.
My code is as follows:
public static async Task Main(string[] args)
{
var hostBuilder = new HostBuilder()
.ConfigureAppConfiguration
(
(hostBuilderContext, configurationBuilder) =>
{
configurationBuilder.SetBasePath(Directory.GetCurrentDirectory());
configurationBuilder.AddEnvironmentVariables();
configurationBuilder.AddJsonFile("appsettings.json", optional: true);
}
)
.ConfigureServices
(
(hostBuilderContext, services) =>
{
services.AddHostedService<HostedService>();
services.AddSingleton<ISocketImplementation, SocketImplementation>();
services.AddSingleton<IMessageHandler, MessageHandler>();
}
);
await hostBuilder.RunConsoleAsync();
}
When I use Docker run -d to create the container, the container stops immediately. It doesn't look like RunConsoleAsync() is waiting for ctrl+c or SIGTERM.
I tried GenericHostSample and it behaves the same as well
@srininz77 Can you file issues like this on http://github.com/aspnet/Home?
@davidfowl @srininz77 I moved the issue for @srininz77 to the ASPNET Home repo.