"No git binary found" 和 "npm WARN tar ENOENT: no such file or directory" 在 docker 容器中

"No git binary found" and "npm WARN tar ENOENT: no such file or directory" in docker container

这个 docker 设置上周运行良好。从那时起,唯一真正的变化是一些新的依赖项和一些小的代码更新。这是我用 CircleCI 部署我们的应用程序的方式,自从我上次使用它以来,此配置没有任何变化。

Docker 文件

FROM node:10-alpine as base

EXPOSE 3001

WORKDIR /usr/src/app

COPY server/package.json server/package-lock.json ./

RUN npm install

COPY ./server/ ./

RUN npm run build

CMD ["npm", "run", "server:prod"]

我收到一堆这样的错误:

npm WARN tar ENOENT: no such file or directory, open '/usr/src/app/node_modules/.staging/request-2b86f7e4/index.js'

还有这个错误:

npm ERR! code ENOGIT
npm ERR! Error while executing:
npm ERR! undefined ls-remote -h -t ssh://git@github.com/timsuchanek/codemirror-graphql.git
npm ERR! 
npm ERR! undefined
npm ERR! No git binary found in $PATH

如果删除 package-lock.json 文件,我将不再收到此错误 npm WARN tar ENOENT: no such file or directory。但我仍然得到 No git binary found in $PATH.

注意:如果我 运行 npm install 在 Docker 容器之外,它工作正常。

这让我很生气,因为它突然停止工作,我们无法为我们的应用程序部署任何更新。任何帮助将不胜感激。

编辑:---

我将以下内容添加到 docker 文件(基于下面的答案)并解决了问题。

RUN apk update && apk upgrade && \
    apk add --no-cache bash git openssh

Docker node:alpine 图片的描述说:

To minimize image size, it's uncommon for additional related tools (such as git or bash) to be included in Alpine-based images. Using this image as a base, add the things you need in your own Dockerfile (see the alpine image description for examples of how to install packages if you are unfamiliar).

description

您将需要向具有正确权限的容器添加 ssh 密钥。

检查此以供参考https://medium.com/paperchain/fetching-private-github-repos-from-a-docker-container-273f25ec5a74