反应曲目:在CI中构建Docker图像时找不到,但在本地工作
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它在本地工作的原因是因为我的本地
node_modules
被复制到copy ./ui ./ cople ./ code> step中的容器中。
一旦i
.dockerignore
-dnode_modules
,实现的copy -from = dep/app/package.json/app/app/yarn.lock/yarn.lock/app/node_modules ./将
node_modules
的孩子复制到项目根而不是模块目录。将副本步骤更改为以下问题解决了问题:
The reason it worked locally was because my local
node_modules
was copied into the container in theCOPY ./ui ./
step.Once I
.dockerignore
-dnode_modules
, the realized theCOPY --from=deps /app/package.json /app/yarn.lock /app/node_modules ./
was copying the children ofnode_modules
to the project root instead of the modules directory.Changing the COPY step to the following resolved the issue: