Search code examples
c#.netdeploymentblazorgcloud

Google Cloud Run deployments failing after updating to .NET 9


I am deploying my Blazor Server app via Google Cloud Run. But it has been failing since I updated my project to .NET 9. Do I need to make any specific settings on gCloud? The error I am getting is

The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable within the allocated timeout. This can happen when the container port is misconfigured or if the timeout is too short.

Maybe I am misinterpreting this issue, but the app used to work on port 8080 and it is indeed exposed. What could it be?

Any help would be appreciated. Thanks!

I am exposing the port like this in Program.cs -

var port = Environment.GetEnvironmentVariable("PORT") ?? "8080";
var url = $"http://0.0.0.0:{port}";
app.Run(url);

And I have also set the port to 8080 in gCloud Run Service as well.

Edit - I am deploying directly from the source. The docker image is being created on the cloud itself when I run the "gcloud run deploy" command. Deployment region is us-west1.


Solution

  • I am happy to report that I have fixed my issue. Here's the solution in case someone faces the same issue -

    I added these two in dockerfile

    # Set environment variable for the listening port, as required by Cloud Run
    ENV ASPNETCORE_URLS=http://+:8080
    
    ENV PORT 8080
    

    FYI - I already had EXPOSE 8080 and yet, the above two lines were required. This makes sense, as the error suggested something about PORT 8080. However, I still do not understand why these two lines were required as it was working fine before. I wonder if it is because of the dotnet 9 upgrade. Let me know if anyone has a clue.

    Cheers!