FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build WORKDIR /src COPY [project_name].csproj . RUN dotnet restore COPY . . RUN dotnet publish -c release -o /app FROM mcr.microsoft.com/dotnet/aspnet:6.0 WORKDIR /app EXPOSE 80 EXPOSE 443 COPY --from=build /app . ENTRYPOINT ["dotnet", "[project_name].dll"]
然后再Dockerfile文件所在目录下执行
docker build -t [image_name] .
运行构建后镜像
docker run -it --rm -dp 5200:80 --name [container_name] [image_name]