node.js - 使用 SSH 密钥从 docker 内部的私有存储库安装 npm 模块
问题描述
我为 nodejs 项目制作容器。在项目内部,我使用的是私有存储库。我需要访问它。为此,我正在使用下一个 Dockerfile
FROM node:15
RUN echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan bitbucket.org >> ~/.ssh/known_hosts
COPY keys/ssh_config /root/.ssh/config
COPY keys/bitbucket /root/.ssh/bitbucket
RUN chmod 600 /root/.ssh/bitbucket
RUN npm install -g typescript ts-node
WORKDIR /var/www
EXPOSE 3000
ssh_config 文件是
Host bitbucket.org
IdentityFile /root/.ssh/bitbucket
StrictHostKeyChecking no
在我的 package.json 我添加了下一行
"my-interfaces": "git+ssh://bitbucket.org:MY_USER_NAME/my-interfaces.git#master",
使用 docker-compose 构建容器后,我登录容器并运行
npm i
,但最后我看到下一个错误
npm ERR! code 128
npm ERR! command failed
npm ERR! command git ls-remote ssh://git@bitbucket.org/MY_USER_NAME/my-interfaces.git
npm ERR! Permission denied (publickey).
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.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-04-30T08_19_38_999Z-debug.log
我尝试了另一种方法,我在容器内生成 SSH 密钥并将公钥添加到 bitbucket,但我看到了相同的错误消息。
解决方案
推荐阅读
- r - 如何将多步函数应用于多个数据集,然后将结果组合到新数据集中
- java - 倒计时动画类在某些设备上的工作方式不同
- loops - 如何在ansible的循环中使用任务变量?
- flutter - Flutter - 如何将“FlatButton”转换为“RaisedButton”(切换深色/浅色主题)?+ 文字样式
- flutter - 在 TextFormField 验证器 Flutter 中调用异步函数
- javascript - 使用 react router dom 滚动到新页面上的特定 div
- linux - 如何在 perf 程序中启用硬件事件?
- c# - 需要完整路径保存的 Visual Studio 集成 SQL 数据库
- firebase - 设置“触发电子邮件”Firebase 扩展
- r - R如何将一列添加到csv文件列表中