【问题标题】:=> ERROR [5/5] RUN npm install or yarn in Dockerfile=> 错误 [5/5] 在 Dockerfile 中运行 npm install 或 yarn
【发布时间】:2022-01-18 10:11:12
【问题描述】:

我正在尝试 Dockerise 一个 React 应用程序,但是当它到达安装 npm 的命令时会引发错误。

我的 Dockerfile 包含:

# pull official base image
FROM node:12.6.0-alpine


# set working directory
RUN mkdir /app
COPY . /app
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH

RUN yarn

# start app
CMD ["npm", "start"]

当它到达运行npm install或yarn的命令时错误是这样的:

[5/5] RUN yarn:                                                                                                                             
#9 0.725 yarn install v1.16.0                                                                                                                  
#9 0.789 info No lockfile found.                                                                                                               
#9 0.801 warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.   
#9 0.809 [1/4] Resolving packages...
#9 1.507 warning axios@0.19.2: Critical security vulnerability fixed in v0.21.1. For more information, see https://github.com/axios/axios/pull/3410
#9 8.363 warning formik > create-react-context > fbjs > core-js@1.2.7: core-js@<3.4 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
#9 40.35 error Couldn't find the binary git
#9 40.35 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
------
executor failed running [/bin/sh -c yarn]: exit code: 1

【问题讨论】:

    标签: reactjs docker npm yarn-v2


    【解决方案1】:

    #9 40.35 error 找不到二进制 git

    解决方案:在你的 docker 镜像中安装 git。

    【讨论】:

      【解决方案2】:

      像这样在你的镜像中安装 git

      FROM node:12.6.0-alpine
      RUN apk update && apk add git
      
      # set working directory
      RUN mkdir /app
      COPY . /app
      WORKDIR /app
      ENV PATH /app/node_modules/.bin:$PATH
      
      RUN yarn
      
      # start app
      CMD ["npm", "start"]
      

      【讨论】:

      • 谢谢,它有效。另外,我目前正在研究 React(UI),每次我在 VS 编辑器上更改代码时,我都需要查看 dom 上的更改,有没有办法让容器监听更改并立即更新图像? . - 不确定,但可能是音量或类似的东西,这是我的 docker 文件 FROM node:12.6.0-alpine RUN apk update && apk add git # set working directory RUN mkdir /app COPY 。 /app WORKDIR /app ENV PATH /app/node_modules/.bin:$PATH RUN yarn # 启动应用 CMD ["npm", "start"]
      猜你喜欢
      • 2021-11-25
      • 2020-05-12
      • 2018-11-15
      • 1970-01-01
      • 1970-01-01
      • 2014-07-19
      • 1970-01-01
      • 1970-01-01
      • 2020-02-20
      相关资源
      最近更新 更多