[英]Adding private ssh key to docker
I am trying to add my ssh private key to docker, my Dockerfile is as follows: 我正在尝试将ssh私钥添加到docker,我的Dockerfile如下:
ARG key
RUN echo $key > panaxea-key
RUN chmod 600 panaxea-key
RUN eval $(ssh-agent -s) && ssh-add panaxea-key
Console output: 控制台输出:
Step 10/14 : RUN echo $key > panaxea-key
---> Using cache
---> 8ee023dba45e
Step 11/14 : RUN chmod 600 panaxea-key
---> Using cache
---> b7c42a9c5268
Step 12/14 : RUN eval $(ssh-agent -s) && ssh-add panaxea-key
---> Running in 9895e087cea5
Agent pid 9
Enter passphrase for panaxea-key: The command '/bin/sh -c eval $(ssh-agent -s) && ssh-add panaxea-key' returned a non-zero code: 1
dario@dario-X750JB:~/Panaxea_Docker$
Any advice? 有什么建议吗? My key doesn't have a passphrase
我的钥匙没有密码
If your key doesn't have a passphrase and ssh-add is asking you for one, it means ssh-add could not understand your key file. 如果您的密钥没有密码,并且ssh-add要求您输入密码,则意味着ssh-add无法理解您的密钥文件。 The culprit is
echo $key > panaxea-key
. 罪魁祸首是
echo $key > panaxea-key
。 You'll see that the file is a single line of text now and all the newlines have disappeared. 您会看到文件现在是一行文本,所有换行符都消失了。
Use echo "$key" > panaxea-key
instead. 使用
echo "$key" > panaxea-key
代替。
This should get it to work, but the warnings about embedding a private key inside a docker image still stand. 这应该可以使其正常工作,但是关于在Docker映像中嵌入私钥的警告仍然存在。 How you get around that depends on exactly what you're trying to accomplish, but I feel like that's a different question altogether.
如何解决问题取决于您要完成的工作,但是我觉得这完全是一个不同的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.