Dockerfile找不到我的私有ssh密钥

时间:2014-02-19 18:55:58

标签: apache ssh docker

我正在尝试构建一个dockerfile,以便克隆一个私有仓库。我相信我已经添加了正确的代码来执行此操作,但它不断抛出此错误:

build: id_rsa: no such file or directory

我已经确定路径是正确的,密钥就在那里,并尝试了许多其他解决方案,例如在ssh_config中取消注释IdentityFile无济于事。这是我的dockerfile:

FROM ubuntu:latest
MAINTAINER John Fink <john.fink@gmail.com>
RUN apt-get update # Thu Nov  7 22:40:44 EST 2013


RUN apt-get install -y mysql-client mysql-server apache2 libapache2-mod-php5 pwgen      python-setuptools vim-tiny php5-mysql git

RUN easy_install supervisor

ADD id_rsa /root/.ssh/id_rsa
ADD known_hosts /root/.ssh/known_hosts
RUN echo " IdentityFile /root/.ssh/id_rsa" >> /etc/ssh/ssh_config

RUN cd /var/www
RUN git clone git@dev.ploonky.com:eric/hartshorn-portraiture.git

ADD ./start.sh /start.sh
ADD ./foreground.sh /etc/apache2/foreground.sh
ADD ./supervisord.conf /etc/supervisord.conf
RUN chmod 755 /start.sh
RUN chmod 755 /etc/apache2/foreground.sh
EXPOSE 80
CMD ["/bin/bash", "/start.sh"]

2 个答案:

答案 0 :(得分:5)

您的id_rsa文件是否在您的Dockerfile所在的当前目录中?尝试指定它的完整路径

答案 1 :(得分:1)

我做了一个更强力的版本,以及

FROM ubuntu
RUN apt-get -yq install ssh
ADD .ssh /root/.ssh/
CMD     bash

努力失败 -

sven@mini:~/src/docker/tmp$ docker run -rm -t -i test 
root@810a2b43ed12:/# ls -la /root
total 20
drwx------  3 root root 4096 Feb 20 04:12 .
drwxr-xr-x 45 root root 4096 Feb 20 04:17 ..
-rw-r--r--  1 root root 3106 Apr 19  2012 .bashrc
-rw-r--r--  1 root root  140 Apr 19  2012 .profile
drwx------  2 1000 1000 4096 Feb 20 04:04 .ssh
root@810a2b43ed12:/# ssh sven@192.168.1.220
Bad owner or permissions on /root/.ssh/config
root@810a2b43ed12:/# chown -R root:root /root/.ssh/
root@810a2b43ed12:/# ssh sven@192.168.1.220
Linux mini 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64

所以我说你只需要做一个

RUN chown -R root:root /root/.ssh

你应该好好去。