The first time you build the dockerfile that comes with the initialization project, the content is as follows:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
#FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
#WORKDIR /app
#EXPOSE 80
#EXPOSE 443
#
#FROM mcr.microsoft.com/dotnet/sdk:5.0-buster AS build
#WORKDIR /src
#COPY ["WaterCloud.Web/WaterCloud.Web.csproj", "WaterCloud.Web/"]
#RUN dotnet restore "WaterCloud.Web/WaterCloud.Web.csproj"
#COPY . .
#WORKDIR "/src/WaterCloud.Web"
#RUN dotnet build "WaterCloud.Web.csproj" -c Release -o /app/build
#
#FROM build AS publish
#RUN dotnet publish "WaterCloud.Web.csproj" -c Release -o /app/publish
#
#FROM base AS final
#WORKDIR /app
#COPY --from=publish /app/publish .
#RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#RUN echo 'Asia/Shanghai' >/etc/timezone
#ENTRYPOINT ["dotnet", "WaterCloud.Web.dll"]
Hold down shift in the root directory and right-click to open powershell or directly open the cmd command panel and execute the following build command:
docker build -t yzzxWeb -f ./WaterCloud.Web/Dockerfile .
Error reported:
=> 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
This is due to more information also mentioned on docker hub:
As part of the .NET 5.0 release, all .NET Docker images (including .NET Core 2.1 and 3.1) have been converted to a new set of Docker repositories described below. Updates to supported tags in legacy repository locations will continue to be made for backwards compatibility. Please update any repository references to these new names. For more information, see the .NET 5.0 repository rename announcement.
Solution:
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
Change the above code to the following:
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
That is, remove the -buster-slim code