docker build --build-arg SSH_PRIVATE_KEY=“$(cat ~/.ssh/id_rsa)” returning empty

寵の児 提交于 2020-01-14 04:17:27

问题


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

the result is

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

Removing intermediate container c8d6e3c88cd8

In the dockerfile I have 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.

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


回答1:


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

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.



来源:https://stackoverflow.com/questions/59541238/docker-build-build-arg-ssh-private-key-cat-ssh-id-rsa-returning-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!