Dockerfile can't find my private ssh key

I’m trying to build a dockerfile so that it clones a private repo. I’ve believe I’ve added the right code to do this, but it keeps throwing this error:

build: id_rsa: no such file or directory

I’ve made sure the path is right and that the key is in there, and tried numerous other solutions proposed on here such as uncommenting the IdentityFile in ssh_config to no avail. Here is my dockerfile:

  • Error starting docker daemon
  • MySql.Data.MySqlClient.MySqlException using ServiceStack ORMLite
  • How to change docker ip address on centos 7?
  • Docker wont build anymore after accedently trying to delete windowsfilter folder
  • Change default route in docker container
  • How to run docker container with -i -t options using TeamCity?
  • FROM ubuntu:latest
    MAINTAINER John Fink <>
    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
    ADD ./ /
    ADD ./ /etc/apache2/
    ADD ./supervisord.conf /etc/supervisord.conf
    RUN chmod 755 /
    RUN chmod 755 /etc/apache2/
    EXPOSE 80
    CMD ["/bin/bash", "/"]

  • Docker pull error: no space left on device
  • Docker-swarm error: read-only file system
  • How can I use nginx to forward incoming requests from a certain URL on port 80 to various docker applications
  • Mismatch in mount path
  • How to run maven test with mysql running in docker
  • docker find container by pid of inside process
  • 2 Solutions collect form web for “Dockerfile can't find my private ssh key”

    Is your id_rsa file in the current directory where your Dockerfile is? Try specifying the full path to it

    I did a more brute force version to see, and

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

    fails hard –

    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@
    Bad owner or permissions on /root/.ssh/config
    root@810a2b43ed12:/# chown -R root:root /root/.ssh/
    root@810a2b43ed12:/# ssh sven@
    Linux mini 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64

    so I’d say you just need to do a

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

    and you should be good to go.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.