docker build --build-arg SSH_PRIVATE_KEY =''$(猫〜/ .ssh / id_rsa)''返回空 [英] docker build --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)" returning empty

查看:207
本文介绍了docker build --build-arg SSH_PRIVATE_KEY =''$(猫〜/ .ssh / id_rsa)''返回空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够读取文件〜/ .ssh / id_rsa 的内容,并将其传递给映像的构建阶段。当我使用命令 docker build --build-arg SSH_PRIVATE_KEY = $(cat〜/ .ssh / id_rsa) 时,我尝试在容器内部回显该内容

I want to be able to read the contents of the file ~/.ssh/id_rsa and pass the same to my build stage of the image. When I use the command docker build --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)" and then I try to echo that inside the container during a build, I get empty.

RUN echo "$SSH_PRIVATE_KEY" > /priv_key \
    && cat /priv_key

结果为

Step 6/14 : RUN echo "$SSH_PRIVATE_KEY" > /priv_key     && cat /priv_key
 ---> Running in c8d6e3c88cd8

Removing intermediate container c8d6e3c88cd8

在dockerfile中,我 ARG SSH_PRIVATE_KEY

In the dockerfile I have ARG SSH_PRIVATE_KEY.

但是当我使用 docker build --build- arg SSH_PRIVATE_KEY =虚拟文本 我可以在日志中看到它。

But when I use a dummy text like docker build --build-arg SSH_PRIVATE_KEY="dummy text" I can see it in the logs.

这会导致我的私钥格式无效,因为它是空的。
RUN回显 $ {SSH_PRIVATE_KEY}>> /root/.ssh/id_rsa

This causes my private key to be in invalid format since it is empty. RUN echo "${SSH_PRIVATE_KEY}" >> /root/.ssh/id_rsa

我做错了什么或没有做什么?谢谢

What am I doing wrong or what is it that am not doing? Thank you

推荐答案

我继续使用 ONVAULT 工具来处理ssh键。 https://github.com/dockito/vault

I went ahead and used ONVAULT toool to handle the ssh keys. https://github.com/dockito/vault.

此外,我还误配置了 .ssh / config 文件。新文件如下所示:

Also, I had misconfigured my .ssh/config file. The new file looks like this

Host *
  IgnoreUnknown AddKeysToAgent,UseKeychain
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa 

我希望它对以后的人有所帮助。

I hope it helps someone in future.

这篇关于docker build --build-arg SSH_PRIVATE_KEY =''$(猫〜/ .ssh / id_rsa)''返回空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆