build-flow.api/Dockerfile
xiangning ff5a95b3c9 fix(docker): 显式 COPY appsettings.json 进镜像 + 设 Production 环境
问题:dotnet publish 默认行为不稳定,运行时镜像内缺失 appsettings.json,
导致 api 容器启动时连 MongoDB 127.0.0.1:17017 失败(应用了默认配置)。

修复:
- Dockerfile runtime 阶段显式 COPY src/BuildFlow.Host/appsettings.json
- 设 ASPNETCORE_ENVIRONMENT=Production(配合 Secrets 覆盖)
- appsettings.Secrets.json 仍靠 compose volume 挂载注入,不进镜像
2026-07-17 15:06:40 +08:00

28 lines
1.2 KiB
Docker
Raw 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.

# BuildFlow API (.NET 10) 多阶段构建
# dotnet 基础镜像:devops 构建机本地已预拉完整缓存(docker pull mcr.microsoft.com/dotnet/sdk:10.0),
# buildkit 直接 CACHED 命中,无需联网。如构建机镜像被清理,需重新 docker pull 预热。
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
# 先拷贝 sln 和 props,利用层缓存恢复 NuGet
COPY BuildFlow.slnx Directory.Build.props ./
COPY src/ ./src/
# 还原 + 发布 Host (含全部模块)
RUN dotnet publish src/BuildFlow.Host/BuildFlow.Host.csproj -c Release -o /app/publish /p:UseAppHost=false
# 运行时镜像(devops 本地已预拉缓存,buildkit CACHED 命中)
FROM mcr.microsoft.com/dotnet/aspnet:10.0
WORKDIR /app
COPY --from=build /app/publish ./
# 显式确保 appsettings.json 进镜像(dotnet publish 默认行为不稳定,曾出现缺失)
# appsettings.Secrets.json 不进镜像(.dockerignore 已排除),生产靠 compose volume 挂载注入
COPY src/BuildFlow.Host/appsettings.json /app/appsettings.json
# 容器内监听 5667 (与 appsettings 一致), 但绑定 0.0.0.0 以便外部访问
ENV ASPNETCORE_URLS=http://0.0.0.0:5667
ENV ASPNETCORE_ENVIRONMENT=Production
EXPOSE 5667
ENTRYPOINT ["dotnet", "BuildFlow.Host.dll"]