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:

  • Interact with kafka docker container from outside of docker host
  • Google Cloud Shell, Upgrade Docker from 1.9.1, it's impossible?
  • Volume is not shared between nodes of Docker Swarm
  • Changing Kafka Configuration on spotify/kafka Dockerfile
  • Httplib2 exception raised when calling Twilio from python
  • PHP cannot write in docker container
  • 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", "/"]

  • What causes flume with GCS sink to throw a OutOfMemoryException
  • Docker daemon wont start even after adding user/deleting host environment var etc
  • How to manage code changes in rails with docker
  • How to customize the configuration file of the official PostgreSQL Docker image?
  • Getting error while runnig neo4j-mazerunner project
  • How to make Hazelcast nodes installed in docker on different aws instances interact with each other?
  • 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.