ql_apimanager_backend/Dockerfile

29 lines
892 B
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 使用 .NET 8.0 SDK 作为构建环境
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
# 1. 复制解决方案文件和所有项目的.csproj文件自动包含所有项目
COPY *.sln .
COPY */*.csproj ./
# 为每个项目创建目录并移动.csproj文件到正确位置
RUN for file in $(ls *.csproj); do mkdir -p ${file%.*}/ && mv $file ${file%.*}/; done
# 2. 恢复所有项目的依赖
RUN dotnet restore "Apimanager_backend.sln"
# 3. 复制所有源代码
COPY . .
# 4. 构建并发布主项目假设Apimanager_backend是启动项目
WORKDIR /src/Apimanager_backend
RUN dotnet publish -c Release -o /app/publish --no-restore
# 5. 使用运行时镜像
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app/publish .
# 6. 配置容器
ENV ASPNETCORE_ENVIRONMENT=Development
EXPOSE 8080
ENTRYPOINT ["dotnet", "Apimanager_backend.dll"]