如何在Google Cloud中使用.Net Core 3.0映像? [英] How can I use .Net Core 3.0 image in Google Cloud?

查看:84
本文介绍了如何在Google Cloud中使用.Net Core 3.0映像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Cloud托管.Net Core 2.2应用程序,但我想将其更新为3.0.我的app.yaml看起来像这样

I'm using Google Cloud to host my .Net Core 2.2 application, but I want to update it to 3.0. My app.yaml looks like this

service: api
runtime: aspnetcore
env: flex

我知道我可以在runtime部分中指定.Net Core版本.但是Google Cloud Container Registry没有.Net Core 3.0.我已经在此处进行了检查.

I know that I can specify the .Net Core version in runtime section. But Google Cloud Container Registry doesn't have .Net Core 3.0. I've checked it here.

那我应该做一个自定义的容器吗?我对docker的使用经验为零.也许有一个随时可以使用的容器.

Should I make a custom container then? I have zero experience with docker. Maybe there is a ready-to-go container somehow.

我没有在公共容器注册表中找到任何更新.Net Core映像的路线图.

I didn't found any roadmap for update .Net Core images in public Container Registry.

@update

正在工作!

我的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"]

还有我的新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

还有我的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'

推荐答案

由于您已经在使用Flexible环境,因此一种可能的解决方案是将运行时设置为custom,然后使用Dockerfile来指定您想要的映像,在这种情况下是.Net Core 3.0.

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.

例如,可以将app.yaml文件重写为:

As an example, the app.yaml file can be re-written like such:

service: api
runtime: custom
env: flex

我们还可以在官方

同样,这只是可能的解决方案之一. Google具有

Again, this is only one of the possible solutions. Google has an article that describes 4 ways you can deploy a .Net Core application. Granted, it is a few years old, but concepts should still apply. As an overview, you can:

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

这篇关于如何在Google Cloud中使用.Net Core 3.0映像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆