【问题标题】:Unable to find ssh key using phusion/base-image无法使用 phusion/base-image 找到 ssh 密钥
【发布时间】:2015-12-07 06:45:37
【问题描述】:

我实际上是在使用带有 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

我做错了什么?

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

【问题讨论】:

    标签: ssh docker dockerfile


    【解决方案1】:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-17
      • 2020-03-29
      • 2020-12-27
      • 2021-11-29
      • 1970-01-01
      • 2021-04-03
      • 1970-01-01
      • 2017-04-28
      相关资源
      最近更新 更多