简体   繁体   English

如何在 Google Cloud 中使用 .Net Core 3.0 映像?

[英]How can I use .Net Core 3.0 image in Google Cloud?

I'm using Google Cloud to host my.Net Core 2.2 application, but I want to update it to 3.0.我正在使用 Google Cloud 托管 my.Net Core 2.2 应用程序,但我想将其更新到 3.0。 My app.yaml looks like this我的app.yaml看起来像这样

service: api
runtime: aspnetcore
env: flex

I know that I can specify the.Net Core version in runtime section.我知道我可以在runtime部分指定 .Net Core 版本。 But Google Cloud Container Registry doesn't have.Net Core 3.0.但是 Google Cloud Container Registry 没有 .Net Core 3.0。 I've checked it here .我已经在这里检查过了。

Should I make a custom container then?那我应该制作一个自定义容器吗? I have zero experience with docker .我对docker的经验为零。 Maybe there is a ready-to-go container somehow.也许不知何故有一个现成的容器。

I didn't found any roadmap for update.Net Core images in public Container Registry.我没有在公共 Container Registry 中找到 update.Net Core 映像的任何路线图。

@update @更新

Solution解决方案

It's working!它正在工作!

My dockerfile looks like this:我的dockerfile看起来像这样:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY MyProject.csproj ./
RUN dotnet restore 

# Copy everything else and build
COPY . ./
RUN dotnet publish /app/MyProject.csproj -c Release -o ./out --nologo

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/out/ .
EXPOSE 8080
ENV ASPNETCORE_URLS=http://*:8080
ENV ASPNETCORE_ENVIRONMENT=production
ENV TAPTAKE_SEED=false
ENTRYPOINT ["dotnet", "MyProject.dll"]

And my new app.yaml还有我的新app.yaml

service: api
runtime: custom
env: flex
env_variables:
  ASPNETCORE_ENVIRONMENT: "production"
  
# Note this manual scaling is only for development
manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 4
  disk_size_gb: 10
 

And my cloudbuild.yaml :还有我的cloudbuild.yaml

steps:

# Build
- name: 'gcr.io/cloud-builders/dotnet'
  args: [ 'publish', '-c', 'Release' ]
  dir: 'MyProject'
 
# Migrations
- name: 'gcr.io/cloud-builders/dotnet'
  args: [ 'ef', 'database', 'update' , '--configuration', 'Production']
  dir: 'MyProject'
  env:
    - 'ASPNETCORE_ENVIRONMENT=production'

# DEPLOY
- name: 'gcr.io/cloud-builders/gcloud'
  args: ['app','deploy','MyProject/bin/Release/netcoreapp3.1/publish/app.yaml', '--verbosity=debug']
timeout: '1200s'

Since you are already using the Flexible environment, one possible solution would be to set the runtime to custom and then use a Dockerfile to specify the image that you would like, which in this case is.Net Core 3.0.由于您已经在使用灵活环境,一种可能的解决方案是将运行时设置为自定义,然后使用 Dockerfile 指定您想要的图像,在本例中为 .Net Core 3.0。

As an example, the app.yaml file can be re-written like such:例如,app.yaml 文件可以这样重写:

service: api
runtime: custom
env: flex

We could also write the Dockerfile on top of the example given in the official docker docs我们还可以在官方docker 文档中给出的示例之上编写 Dockerfile

FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "aspnetapp.dll"]

Again, this is only one of the possible solutions.同样,这只是可能的解决方案之一。 Google has an article that describes 4 ways you can deploy a.Net Core application . Google 有一篇文章描述了部署 .Net Core 应用程序的 4 种方法 Granted, it is a few years old, but concepts should still apply.当然,它已经有几年历史了,但概念仍然应该适用。 As an overview, you can:作为概述,您可以:

  • Deploy from Visual Studio directly using the Cloud Tools for Visual Studio extension使用 Cloud Tools for Visual Studio 扩展直接从 Visual Studio 部署
  • Deploy a Framework Dependent Deployment bundle with "dotnet publish"使用“dotnet publish”部署框架相关部署包
  • Deploy to App Engine flexible environment with a custom Dockerfile使用自定义 Dockerfile 部署到 App Engine 柔性环境
  • Deploy to Container Engine with a custom Dockerfile使用自定义 Dockerfile 部署到容器引擎

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 ODBC 连接与 Visual Studio 2019 和 .NET Core 3.0 结合使用? - How can I use ODBC connections with Visual Studio 2019 and .NET Core 3.0? 如何在第三个项目中引用和使用 .NET Core 3.0 和 .NET EF 4.7 项目,并使用它们的数据库连接? - How can I reference and use .NET Core 3.0 and .NET EF 4.7 projects, in a third project, and use their database connections? 如何在 .net core 3.0 中执行一次工作服务? - How can i execute a worker service once in .net core 3.0? 我如何在谷歌云 function .NET Core 3.1 上启用 CORS - How can i enable CORS on google cloud function .NET Core 3.1 如何在.net 2.0项目中使用.net 3.0类? - How can I use .net 3.0 class in .net 2.0 project? 我可以在我的 ApplicationLogic 项目(net standard 2.1)中的 MVC(.net core 3.0)项目中使用视图模型吗? - Can I use viewmodels in my MVC(.net core 3.0) project in my ApplicationLogic project (net standard 2.1) 如何在 .NET 核心中裁剪图像? - How can I crop an image in .NET core? 我可以在微软的 Bot Framework 上使用 .NET core 3.0 SDK 吗? - Can I use .NET core 3.0 SDK on Microsoft's Bot Framework? 我可以在 ASP.net 核心 3.0 的 [Route(“x/{id}”) 中使用变量吗? - Can I use an variable in the [Route(“x/{id}”) of ASP.net core 3.0? 如何在.NET Core中使用OpenAL? - How can I use OpenAL in .NET Core?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM