NAS 部署时 web 阶段失败: failed to solve: failed to compute cache key: "/deploy/nginx/web.conf": not found 根因:fuellog-web/Dockerfile 的 `COPY deploy/nginx/web.conf` 是相对 build context 的。web Dockerfile 的 context = fuellog-web/,所以它在找 fuellog-web/deploy/nginx/web.conf —— 实际文件在仓库根的 deploy/nginx/web.conf, 出 context 了,build 报错。 修法:把 web.conf 移到 web 自己的 build context 内,放到 fuellog-web/nginx/web.conf。 Dockerfile COPY 改成 `COPY nginx/web.conf`。同时 deploy/docker-compose.dev.yml 的 bind-mount 路径从 ./nginx/web.conf 改成 ../fuellog-web/nginx/web.conf。 deploy/nginx/web.conf 保留为重定向注释占位,deploy/ 目录在 git 里仍是 有效的,避免外部引用突然找不到。 期间顺带:dev compose 之前 `./nginx/web.conf` 路径是相对 deploy/,符合 compose 的"相对 compose 文件找依赖"约定,改成 `../fuellog-web/nginx/web.conf` 也保持一致;prod compose 不动,它只 build 不直接挂文件。 未做(留待后续): - 把 deploy/nginx/web.conf 直接 rm 掉(目前用"重定向注释"占位); PowerShell 没有 mavis-trash,删文件会被拦。后续可改用 .gitkeep + 真删 流程,或干脆用符号链接 - fuellog-web/deploy/ 之类的隔离目录,等真正需要再说
42 lines
950 B
Docker
42 lines
950 B
Docker
# 多阶段:Vite 构建 -> Nginx 静态服务
|
|
# Builder
|
|
FROM node:20-alpine AS builder
|
|
|
|
# 国内可换源
|
|
# RUN sed -i 's|dl-cdn.alpinelinux.org|mirrors.aliyun.com|g' /etc/apk/repositories
|
|
|
|
ENV PNPM_HOME=/pnpm \
|
|
PATH=/pnpm:$PATH
|
|
|
|
# 装 pnpm(用 corepack 更省事)
|
|
RUN corepack enable && corepack prepare pnpm@9.7.1 --activate
|
|
|
|
WORKDIR /src
|
|
|
|
# 利用 layer 缓存
|
|
COPY package.json pnpm-lock.yaml* ./
|
|
RUN pnpm install --frozen-lockfile
|
|
|
|
COPY . .
|
|
RUN pnpm build
|
|
|
|
# Runner:用 nginx 提供静态资源 + 反代 /api
|
|
FROM nginx:1.27-alpine
|
|
|
|
# 删掉默认配置
|
|
RUN rm /etc/nginx/conf.d/default.conf
|
|
|
|
# 我们的反代 + SPA fallback 配置
|
|
COPY nginx/web.conf /etc/nginx/conf.d/web.conf
|
|
|
|
# 静态产物
|
|
COPY --from=builder /src/dist /usr/share/nginx/html
|
|
|
|
# 健康检查
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD wget -q -O- http://127.0.0.1/ > /dev/null || exit 1
|
|
|
|
EXPOSE 80
|
|
|
|
CMD ["nginx", "-g", "daemon off;"]
|