首页 > 解决方案 > 从 docker 容器访问私有存储库作为 npm 依赖项

问题描述

我正在尝试在构建过程中注入我的 ssh

docker build --ssh default=C:\Users\***\.ssh\id_rsa .

// package.json
"airbase-common": "git+ssh://git@bitbucket.org/******/airbase-common.git"

// error
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git@bitbucket.org/******/airbase-common.git
npm ERR!
npm ERR! Host key verification failed.
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.

提前致谢

标签: docker

解决方案


我找到了解决方案:如果有人像我一样在 Windows 环境中构建他的图像,你应该将 .ssh 文件夹作为你的 Dockerfile 的邻居

// Dockerfile

FROM node:12.16 AS builder
WORKDIR /app
COPY ./package.json ./

RUN mkdir /root/.ssh/
COPY  .ssh /root/.ssh
RUN chmod 700 /root/.ssh/
RUN chmod 644 /root/.ssh/id_rsa.pub
RUN chmod 600 /root/.ssh/id_rsa
VOLUME [ "/root/.ssh" ]
RUN npm install
.... etc

推荐阅读