无法使用phusion / base-image找到ssh密钥

时间:2015-06-29 14:18:12

标签: ssh docker dockerfile

我实际上使用了具有phusion / baseimage的Docker,我需要通过ssh连接。

在github存储库(https://github.com/phusion/baseimage-docker)中,在底部写道,要使用我们的自定义公钥,我们必须执行以下操作:

## Install an SSH of your choice.
ADD your_key.pub /tmp/your_key.pub
RUN cat /tmp/your_key.pub >> /root/.ssh/authorized_keys && rm -f /tmp/your_key.pub

事实是,当我需要添加我的公钥时,如下所示:

ADD /home/thomas/.ssh/id_rsa.pub /tmp/id_rsa.pub
RUN cat /home/thomas/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys && rm -f /home/thomas/.ssh/id_rsa.pub

我的docker build中出现此错误。在我的shell命令中堆栈:

sudo docker build .
Sending build context to Docker daemon 12.29 kB
Sending build context to Docker daemon 
Step 0 : FROM phusion/baseimage:0.9.16
 ---> 5a14c1498ff4
Step 1 : MAINTAINER Thomas DUPOND <tdupond@gmail.com>
 ---> Using cache
 ---> 96e99cf37971
Step 2 : CMD ["/sbin/my_init"]
 ---> Using cache
 ---> 4e3c1c0697ac
Step 3 : RUN rm -f /etc/service/sshd/down
 ---> Using cache
 ---> 4d856cc02b9d
Step 4 : RUN /etc/my_init.d/00_regen_ssh_host_keys.sh
 ---> Using cache
 ---> eab6eb3a6630
Step 5 : ADD /home/thomas/.ssh/id_rsa.pub /tmp/id_rsa.pub
2015/06/29 16:11:13 /home/thomas/.ssh/id_rsa.pub: no such file or directory

我做错了什么?

注意:我的密钥是使用rsa从4096生成的。它位于/home/thomas/.ssh目录中,名为id_rsa.pub

1 个答案:

答案 0 :(得分:0)

Docker ADD在Dockerfile目录中查找。 在docker build命令之前运行它:

cp /home/thomas/.ssh/id_rsa.pub .

容器中的命令可以访问文件/tmp/id_rsa.pub。它无法访问/home/thomas/.ssh/id_rsa.pub。 它应该是这样的:

ADD id_rsa.pub /tmp/id_rsa.pub
RUN cat /tmp/id_rsa.pub >> /root/.ssh/authorized_keys && rm -f /tmp/id_rsa.pub