反应曲目:在CI中构建Docker图像时找不到,但在本地工作

发布于 2025-01-28 07:51:42 字数 8 浏览 1 评论 0原文

continue

I have a Dockerfile to build a React app and copy the build to an Nginx container.

FROM node:14-buster-slim AS node-base

FROM node-base as deps
WORKDIR /app

COPY ./ui/package.json ./ui/yarn.lock ./ui/.npmrc ./
RUN yarn install --frozen-lockfile

FROM node-base as build-ui
WORKDIR /app

COPY ./ui ./
COPY --from=deps /app/package.json /app/yarn.lock /app/node_modules ./
RUN yarn run build

FROM nginx:1.21-alpine as ui-server
WORKDIR /usr/share/nginx/html

COPY --from=build-ui /app/build .

COPY ./ui/nginx/nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

Locally, the build works without issue. In CI however, it fails to build:

#14 [build-ui 4/4] RUN yarn run build
#14 0.490 yarn run v1.22.17
#14 0.523 $ react-scripts build
#14 0.535 /bin/sh: 1: react-scripts: not found
#14 0.545 error Command failed with exit code 127.
#14 0.546 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
#14 ERROR: process "/bin/sh -c yarn run build" did not complete successfully: exit code: 127

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以笙箫默 2025-02-04 07:51:42

它在本地工作的原因是因为我的本地node_modules被复制到copy ./ui ./ cople ./ code> step中的容器中。

一旦i .dockerignore -d node_modules,实现的copy -from = dep/app/package.json/app/app/yarn.lock/yarn.lock/app/node_modules ./将node_modules的孩子复制到项目根而不是模块目录。

将副本步骤更改为以下问题解决了问题:

COPY --from=deps /app/package.json /app/yarn.lock ./
COPY --from=deps /app/node_modules /app/node_modules

The reason it worked locally was because my local node_modules was copied into the container in the COPY ./ui ./ step.

Once I .dockerignore-d node_modules, the realized the COPY --from=deps /app/package.json /app/yarn.lock /app/node_modules ./ was copying the children of node_modules to the project root instead of the modules directory.

Changing the COPY step to the following resolved the issue:

COPY --from=deps /app/package.json /app/yarn.lock ./
COPY --from=deps /app/node_modules /app/node_modules
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文