Docker .net 5 图像
Docker image for .net 5
通常我使用 .net core 3.1 的以下图像,它工作正常。
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
出于实验原因,我开始了一个新的 .net 5 项目并创建了 dockerfile
并具有以下内容
FROM mcr.microsoft.com/dotnet/core/aspnet:5.0-buster-slim AS base
FROM mcr.microsoft.com/dotnet/core/sdk:5.0-buster AS build
并有以下问题:
=> ERROR [internal] load metadata for mcr.microsoft.com/dotnet/core/sdk:5.0-buster 0.2s
=> ERROR [internal] load metadata for mcr.microsoft.com/dotnet/core/aspnet:5.0-buster-slim 0.2s
=> CANCELED [build 1/7] FROM mcr.microsoft.com/dotnet/core/sdk:5.0-buster 0.0s
=> => resolve mcr.microsoft.com/dotnet/core/sdk:5.0-buster 0.0s
=> [internal] load build context 0.0s
=> ERROR [base 1/2] FROM mcr.microsoft.com/dotnet/core/aspnet:5.0-buster-slim 0.0s
=> => resolve mcr.microsoft.com/dotnet/core/aspnet:5.0-buster-slim
据我阅读here,改为:
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
docker hub with more info上也提到了:
As part of the .NET 5.0 release, all .NET Docker images (including
.NET Core 2.1 and 3.1) have transitioned to a new set of Docker
repositories described below. Updates will continue to be made to
supported tags in the old repository locations for backwards
compatibility. Please update any repository references to these new
names. For more information see the .NET 5.0 repository rename
announcement.
编辑:
图片说明:
Image
Comments
mcr.microsoft.com/dotnet/runtime:5.0
.NET 5 multi-architecture: Supports Linux and Windows Nano Server depending on the Docker host.
mcr.microsoft.com/dotnet/aspnet:5.0
ASP.NET Core 5.0 multi-architecture: Supports Linux and Windows Nano Server depending on the Docker host. The aspnetcore image has a few optimizations for ASP.NET Core.
mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim
.NET 5 runtime-only on Linux Debian distro
mcr.microsoft.com/dotnet/aspnet:5.0-nanoserver-1809
.NET 5 runtime-only on Windows Nano Server (Windows Server version 1809)
图片描述reference.
你不必自己写这个。一个快速的方法是使用 dockerfile 生成器,正如 Julio Casal 在本快速教程 https://www.youtube.com/watch?v=wQSuZFd01tY.
中所解释的那样
MyApp 的示例代码如下所示
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
ENV ASPNETCORE_URLS=http://+:80
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["MyApp/MyApp.csproj", "MyApp/"]
RUN dotnet restore "MyApp/MyApp.csproj"
COPY . .
WORKDIR "/src/MyApp"
RUN dotnet build "MyApp.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyApp.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyApp.dll"]
通常我使用 .net core 3.1 的以下图像,它工作正常。
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
出于实验原因,我开始了一个新的 .net 5 项目并创建了 dockerfile
并具有以下内容
FROM mcr.microsoft.com/dotnet/core/aspnet:5.0-buster-slim AS base
FROM mcr.microsoft.com/dotnet/core/sdk:5.0-buster AS build
并有以下问题:
=> ERROR [internal] load metadata for mcr.microsoft.com/dotnet/core/sdk:5.0-buster 0.2s
=> ERROR [internal] load metadata for mcr.microsoft.com/dotnet/core/aspnet:5.0-buster-slim 0.2s
=> CANCELED [build 1/7] FROM mcr.microsoft.com/dotnet/core/sdk:5.0-buster 0.0s
=> => resolve mcr.microsoft.com/dotnet/core/sdk:5.0-buster 0.0s
=> [internal] load build context 0.0s
=> ERROR [base 1/2] FROM mcr.microsoft.com/dotnet/core/aspnet:5.0-buster-slim 0.0s
=> => resolve mcr.microsoft.com/dotnet/core/aspnet:5.0-buster-slim
据我阅读here,改为:
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
docker hub with more info上也提到了:
As part of the .NET 5.0 release, all .NET Docker images (including .NET Core 2.1 and 3.1) have transitioned to a new set of Docker repositories described below. Updates will continue to be made to supported tags in the old repository locations for backwards compatibility. Please update any repository references to these new names. For more information see the .NET 5.0 repository rename announcement.
编辑: 图片说明:
Image | Comments |
---|---|
mcr.microsoft.com/dotnet/runtime:5.0 | .NET 5 multi-architecture: Supports Linux and Windows Nano Server depending on the Docker host. |
mcr.microsoft.com/dotnet/aspnet:5.0 | ASP.NET Core 5.0 multi-architecture: Supports Linux and Windows Nano Server depending on the Docker host. The aspnetcore image has a few optimizations for ASP.NET Core. |
mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim | .NET 5 runtime-only on Linux Debian distro |
mcr.microsoft.com/dotnet/aspnet:5.0-nanoserver-1809 | .NET 5 runtime-only on Windows Nano Server (Windows Server version 1809) |
图片描述reference.
你不必自己写这个。一个快速的方法是使用 dockerfile 生成器,正如 Julio Casal 在本快速教程 https://www.youtube.com/watch?v=wQSuZFd01tY.
中所解释的那样MyApp 的示例代码如下所示
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
ENV ASPNETCORE_URLS=http://+:80
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["MyApp/MyApp.csproj", "MyApp/"]
RUN dotnet restore "MyApp/MyApp.csproj"
COPY . .
WORKDIR "/src/MyApp"
RUN dotnet build "MyApp.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyApp.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyApp.dll"]