问题
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
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.
Should I make a custom container then? I have zero experience with 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.
@update
It's working!
My dockerfile
looks like this:
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
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
:
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'
回答1:
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.
As an example, the app.yaml file can be re-written like such:
service: api
runtime: custom
env: flex
We could also write the Dockerfile on top of the example given in the official docker docs
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. 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
- 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
来源:https://stackoverflow.com/questions/58505180/how-can-i-use-net-core-3-0-image-in-google-cloud