范例,如高深的docker使用 DockerFile配置并不涉及
环境
dotnet 6.0
docker 自行安装
ps: 多层级项目 最好调整目录将Dockerfile移至顶层
解决方案: 可以将Dockerfile移至顶层,后只需要修改为 ./XXX/XXX.csproj 更简洁方便
解决方案:将Nuget.config 移动到顶层 在DockerFile下新增 COPY NuGet.config ./
#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:6.0 AS base
WORKDIR /app
EXPOSE 7195
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["./TestPublic/TestPublic.csproj", "./TestPublic/"]
RUN dotnet restore "./TestPublic/TestPublic.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "./TestPublic/TestPublic.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "./TestPublic/TestPublic.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "TestPublic.dll"]
unzip -d xxx XXXX.zip
ps:zip linux支持好一点,所以压缩为zip
docker images
docker run -d --name public -p 7195:80 public:v1