2
votes

Background

I have a .NET Core 3.1 console application that is a long running process. Basically, some logic running in an infinite loop with a delay each loop.

I'm currently using Visual Studio to package this app up in a docker container and then deploy to a Linux App Service in Azure. This all works. I'm able to publish the docker container to an Azure Container Registry, and then point my Linux App Service to the container. The container starts up successfully, and I'm able to see some console output from my app in the logs displayed in Azure. So, all good? Not quite!

(I know this is generally something you could use a WebJob for (sans containers), but Linux App Services don't support WebJobs yet.)

Problem

The Azure App Service seems to ping my container by default on port 80 to check if my app has started up successfully. But, it's a console app, not a web/asp application. So, understandably, Azure gives me the following error:

2021-01-22T02:12:24.506Z ERROR - Container for site <sitename> did not start within expected time limit. Elapsed time = 230.4560202 sec
2021-01-22T02:12:24.508Z ERROR - Container didnt respond to HTTP pings on port: 80, failing site start. See container logs for debugging.
2021-01-22T02:12:24.553Z INFO  - Stopping site because it failed during startup.

Is there any way to get around this? And no, it can't currently be a Window App Service with a WebJob.

2

2 Answers

1
votes

As a workaround you could use an asp.net core app without endpoints and run your logic in a BackgroundService.

see: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-5.0&tabs=visual-studio

1
votes

Just adding to the workaround shared. You may try configuring the amount of time the platform will wait before it restarts your container.

To do so, set the WEBSITES_CONTAINER_START_TIME_LIMIT app setting to the value you want.

The default value is 230 seconds, and the maximum value is 1800 seconds.

To do this, from the Azure Portal> Navigate to your WebApp > Under Settings blade > Go to “Configuration” > Add the above app setting with ‘Name’ with 1800 as ‘Value’ .

Also, additionally these points:

Do I need to use PORT variable in code for built-in containers? No, PORT variable is not necessary due to automatic port detection. If no port is detected, it defaults to 80.

To manually configure a custom port, use the EXPOSE instruction in the Dockerfile and the app setting, WEBSITES_PORT, with a port value to bind on the container.

Do I need to use WEBSITES_PORT for custom containers? Yes, this is required for custom containers. To manually configure a custom port, use the EXPOSE instruction in the Dockerfile and the app setting, WEBSITES_PORT, with a port value to bind on the container.

Can I use ASPNETCORE_URLS in the Docker image? Yes, overwrite the environmental variable before .NET core app starts. E.g. In the init.sh script: export ASPNETCORE_URLS={Your value}