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:

  • How to run uWSGI and NGINX in different Docker containers
  • Deploying local Docker image (DockerFIle) as local Kubernetes pod
  • How to set Zookeeper dataDir in Docker (fig.yml)
  • Docker - check private registry image version
  • Cannot exec into docker container due to application
  • Vagrant with Docker Provider fails with rsync over ssh
  • 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", "/"]

  • Cannot run webpack-dev-server inside docker
  • dockerfile npm start with harmony
  • How do I get the docker client to trust a self signed cert on the token auth server
  • docker-compose can not retrieve variables from SOME.env files
  • How can I pass arguments to a docker container with a python entry-point script using command?
  • API HOST name from env variable node js
  • 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.