如何在Google Cloud中使用.Net Core 3.0映像? [英] How can I use .Net Core 3.0 image in Google Cloud?
问题描述
我正在使用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