[英]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 @更新
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:
作为概述,您可以:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.