I do not know what is the problem here. The Google Cloud Run gives me this error:
Ready condition status changed to False for Revision ezposappapi-00003-miv with message: Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable. Logs for this revision might contain more information...
I have followed the example from Google here.
This is my Program.cs
:
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args)
{
#if DEBUG
return Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
#endif
#if !DEBUG
string port = Environment.GetEnvironmentVariable("PORT") ?? "8080";
string url = String.Concat("http://0.0.0.0:", port);
return Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>().UseUrls(url);
});
#endif
}
}
The container is running at port 8080 at Google Cloud Run.
This is my DockerFile
:
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["EzPOSAppAPI/EzPOSAppAPI.csproj", "EzPOSAppAPI/"]
RUN dotnet restore "EzPOSAppAPI/EzPOSAppAPI.csproj"
COPY . .
WORKDIR "/src/EzPOSAppAPI"
RUN dotnet build "EzPOSAppAPI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "EzPOSAppAPI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "EzPOSAppAPI.dll"]
There is another error from the logs:
Uncaught signal: 6, pid=1, tid=1, fault_addr=0.
{
"textPayload": "Uncaught signal: 6, pid=1, tid=1, fault_addr=0.",
"insertId": "610768a70008741958ceffb7",
"resource": {
"type": "cloud_run_revision",
"labels": {
"service_name": "ezposappapi",
"project_id": "digilife-software",
"configuration_name": "ezposappapi",
"revision_name": "ezposappapi-00003-miv",
"location": "asia-southeast2"
}
},
"timestamp": "2021-08-02T03:38:15.553951292Z",
"severity": "ERROR",
"labels": {
"instanceId": "00bf4bf02dc90720030c58d69fb03c88335dbcae23dbf8624600d5b3cf9e014ff1bbb38d2b764f1cccc3ada43f158ca49843c576aca917efaa41d8bf51daf846"
},
"logName": "projects/digilife-software/logs/run.googleapis.com%2Fvarlog%2Fsystem",
"receiveTimestamp": "2021-08-02T03:38:15.555133567Z"
}
There is no more error message. I do not know how to fix this. Please help.
EDIT
This is my current attempt it works on my local machine:
Program.cs
:
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
}
Dockerfile:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["EzPOSAppAPI.csproj", "EzPOSAppAPI/"]
RUN dotnet restore "EzPOSAppAPI/EzPOSAppAPI.csproj"
WORKDIR "/src/EzPOSAppAPI"
COPY . .
RUN dotnet build "EzPOSAppAPI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "EzPOSAppAPI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "EzPOSAppAPI.dll"]
This is the run
command:
docker run -dt -v "C:\Users\astef\vsdbg\vs2017u5:/remote_debugger:rw" -v "C:\Users\astef\Documents\Projects\C Sharp\EzPOSAppAPI\EzPOSAppAPI\EzPOSAppAPI:/app" -v "C:\Users\astef\Documents\Projects\C Sharp\EzPOSAppAPI\EzPOSAppAPI:/src/" -v "C:\Users\astef\AppData\Roaming\Microsoft\UserSecrets:/root/.microsoft/usersecrets:ro" -v "C:\Users\astef\AppData\Roaming\ASP.NET\Https:/root/.aspnet/https:ro" -v "C:\Users\astef\.nuget\packages\:/root/.nuget/fallbackpackages3" -v "C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages:/root/.nuget/fallbackpackages" -v "C:\Program Files (x86)\Microsoft\Xamarin\NuGet\:/root/.nuget/fallbackpackages2" -e "DOTNET_USE_POLLING_FILE_WATCHER=1" -e "ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS=true" -e "ASPNETCORE_ENVIRONMENT=Development" -e "ASPNETCORE_URLS=https://+:443;http://+:80" -e "NUGET_PACKAGES=/root/.nuget/fallbackpackages3" -e "NUGET_FALLBACK_PACKAGES=/root/.nuget/fallbackpackages;/root/.nuget/fallbackpackages2;/root/.nuget/fallbackpackages3" -P --name EzPOSAppAPI --entrypoint tail ezposappapi:dev -f /dev/null
How can I set this up on Google Cloud Run
?
UseUrls("http://*:8080")
, but I got the same error. I am not sure if the change is actually being uploaded. I did thisdocker tag ezposappapi asia.gcr.io/digilife-software/ezposappapi
to update the build anddocker push asia.gcr.io/digilife-software/ezposappapi
to push the new build. I am not sure if this is correct. I am new to docker. – Alvin Stefanus