npm install git+ssh 在 docker (node16) 中失败

gra*_*hay 6 git node.js npm docker

谁能解释为什么从 切换node:14-alpine到node:16-alpine会导致 npm install 失败?

 > [ 8/10] RUN --mount=type=ssh npm i:
#14 14.27 npm ERR! code 128
#14 14.28 npm ERR! An unknown git error occurred
#14 14.28 npm ERR! command git --no-replace-objects ls-remote ssh://git@github.com/(somerepo).git
#14 14.28 npm ERR! Warning: Permanently added 'github.com' (RSA) to the list of known hosts.
#14 14.28 npm ERR! git@github.com: Permission denied (publickey).
#14 14.28 npm ERR! fatal: Could not read from remote repository.
#14 14.28 npm ERR! 
#14 14.28 npm ERR! Please make sure you have the correct access rights
#14 14.28 npm ERR! and the repository exists.
Run Code Online (Sandbox Code Playgroud)

这是一个:

git+ssh://git@github.com:someorg/somerepo
Run Code Online (Sandbox Code Playgroud)

依赖性。构建是使用以下命令运行的:

DOCKER_BUILDKIT=1 docker build --ssh default .
Run Code Online (Sandbox Code Playgroud)

我在图像中找不到任何明显的变化,这让我怀疑 npm (从 6.14.15 到 8.1.0),但我找不到任何记录(并且它在容器外工作正常)

编辑:Dockerfile 如下所示:

# syntax=docker/dockerfile:experimental
FROM node:16-alpine

RUN apk --no-cache --virtual build-dependencies add \
    python2 \
    make \
    g++ \
    git \
    openssh

# Download public key for github.com
RUN mkdir -p /root/.ssh && \
    chmod 0700 /root/.ssh && \
    ssh-keyscan github.com >> /root/.ssh/known_hosts

WORKDIR /app/
RUN chown -R node $PWD

RUN apk add postgresql-client
ADD ./service/package.json .

RUN --mount=type=ssh npm i
RUN apk del build-dependencies && rm -r /root/.ssh

ADD ./service/ .

CMD node ./app.js

USER node
Run Code Online (Sandbox Code Playgroud)

我所做的唯一改变是FROM

编辑2:如果我在节点14映像中更新npm(到8.1.3),我会遇到同样的问题。但ssh -Tv git@github.com即使在工作版本中运行也会失败,所以我不知道到目前为止使用了什么黑魔法构建套件

gra*_*hay 1

这似乎是 npm8 和 git+ssh 的问题

使用纱线