【发布时间】:2019-09-03 21:36:25
【问题描述】:
尝试使用 dotnet core webapi 项目上传 docker 映像。
cloud run 的一个要求是监听 8080 端口。
我相信我正在这样做,但是当我在推送到容器注册表后创建云运行服务时,GCP 会返回:
“容器无法启动。无法启动并监听 PORT 环境变量定义的端口。此版本的日志可能包含更多信息。”
本地我有红隼在 8080 上监听。在 8080 上也有容器列表。但是当我按下任何一个时,我都会收到启动失败消息...?对此有何建议或尝试?
@wlhee Here is the LOG from cloud run:
2019-04-13T05:24:53.462592ZHosting environment: Production
2019-04-13T05:24:53.462657ZContent root path: /app
2019-04-13T05:24:53.462678ZNow listening on: http://[::]:80
2019-04-13T05:24:53.462697ZApplication started. Press Ctrl+C to shut down.
2019-04-13T05:28:48.973934834ZContainer terminated by the container manager on signal 9.
"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."
~码头文件
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
ENV ASPNETCORE_URLS=http://+:8080
EXPOSE 8080
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["simplecore.csproj", "simplecore/"]
RUN dotnet restore "simplecore/simplecore.csproj"
COPY . .
WORKDIR "/src/simplecore"
RUN dotnet build "simplecore.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "simplecore.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "simplecore.dll"]
~ HERE IS MY MAIN FROM CORE APP
public static void Main(string[] args)
{
//CreateWebHostBuilder(args).Build().Run();
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
//.UseIISIntegration()
.UseStartup<Startup>()
.UseUrls("http://0.0.0.0:8080/")
.Build();
host.Run();
}
【问题讨论】:
-
您是否看到“logging”中打印的任何日志?
-
@wlhee 这是来自云运行的日志:
2019-04-13T05:24:53.462592ZHosting environment: Production 2019-04-13T05:24:53.462657ZContent root path: /app 2019-04-13T05:24:53.462678ZNow listening on: http://[::]:80 2019-04-13T05:24:53.462697ZApplication started. Press Ctrl+C to shut down. 2019-04-13T05:28:48.973934834ZContainer terminated by the container manager on signal 9.抱歉格式化 -
看起来该应用正在侦听端口 80 而不是 8080?
-
即使我尝试让应用在 8080 端口上侦听它也会失败
-
请关注these instructions并确认您的容器在本地运行。
标签: docker google-cloud-platform asp.net-core-webapi google-cloud-run