title: How to access private GitHub repositories in docker-compose?
body: <p>This is my docker-compose.yml file:</p>
  
  <pre><code>version: '2.1'
  
  services:
  
    users-db:
      container_name: users-db
      build: git@github.com:lukalopusina/flask-microservices-users.git#master:project/db
      volumes:
          - '~/.ssh/github:/root/.ssh/id_rsa'
      ports:
          - 5435:5432  # expose ports - HOST:CONTAINER
      environment:
        - POSTGRES_USER=postgres
        - POSTGRES_PASSWORD=postgres
      healthcheck:
        test: exit 0
  </code></pre>
  
  <p>This is Dockerfile:</p>
  
  <pre><code>FROM postgres
  
  # Disable checking for known_hosts (maybe not working)
  RUN mkdir /root/.ssh &amp;&amp; echo "StrictHostKeyChecking no " &gt; /root/.ssh/config
  
  # run create.sql on init
  ADD create.sql /docker-entrypoint-initdb.d
  </code></pre>
  
  <p>When I run <strong>docker-compose up</strong> I get following error:</p>
  
  <pre><code>Building users-db
  ERROR: Error trying to use git: exit status 128 (Cloning into '/var/lib/docker/tmp/docker-build-git576570106'...
  Host key verification failed.
  fatal: Could not read from remote repository.
  
  Please make sure you have the correct access rights
  and the repository exists.
  )
  </code></pre>
  
  <p>The problem is probably something with ssh permissions but I add my ssh key as mounted volume to container with (or maybe I made some mistake there):</p>
  
  <pre><code>volumes:
      - '~/.ssh/github:/root/.ssh/id_rsa'
  </code></pre>
  
  <p>but still it is not working. How to solve this problem?</p>
  
  <p>This is permissions of ~/.ssh directory (my host machine):</p>
  
  <pre><code>drwx------   2 llopusina llopusina     4096 јун  7 14:22 .ssh
  </code></pre>
  
  <p>and these are the permissions of files in ~/.ssh (my host machine):</p>
  
  <pre><code>-rw-------  1 llopusina llopusina 3243 јун  7 14:15 github
  -rw-r--r--  1 llopusina llopusina  749 јун  7 14:15 github.pub
  -rw-r--r--  1 llopusina llopusina 1326 јун  7 14:35 known_hosts
  </code></pre>