我正在尝试在构建过程中将本地私钥添加到 ssh-agent(docker 映像)。
问题 我已经运行了
eval $(ssh-agent -s)
,一旦 docker 运行 ssh-add /etc/ssh/id_rsa
,我收到以下错误:
Could not open a connection to your authentication agent.
目标: 我需要在 NPM 安装过程中克隆一个私有 git 存储库。这个本地密钥将允许我针对私人存储库进行身份验证。
====输出片段====
Step 8/16 : RUN eval $(ssh-agent -s)
---> Running in 195ffeb1f84f
Agent pid 8
---> 0fcbc89d362f
Removing intermediate container 195ffeb1f84f
Step 9/16 : RUN ssh-add /etc/ssh/id_rsa
---> Running in ae99039e1fba
Could not open a connection to your authentication agent.
The command '/bin/sh -c ssh-add /etc/ssh/id_rsa' returned a non-zero code: 2
您在步骤 8 中运行的代理在您执行步骤 9 时已失效。您需要或一次性执行所有步骤才能使其正常工作。
RUN eval $(ssh-agent -s) && ssh-add /etc/ssh/id_rsa && git checkout .....
为什么不在容器中使用体积?
您可以使用
/etc/ssh/id_rsa
路径将 /root/.ssh/id_rsa
挂载到容器卷中。