Something like this should work (suggested by orip):ssh-agent bash -c 'ssh-add /somewhere/yourkey; git clone email@example.com:user/project.git'if you prefer subshells, you could…
The error message
Host key verification failed. is not complaining about your private key, but rather the host key for github.com. You can do this to add the github hostkey:
ssh-keyscan -t rsa github.com > ~/.ssh/known_hosts
Perhaps you have your reasons, but in general cloning the git repo in to the image is not the preferred way to run your code in a container. Instead, put a Dockerfile at the root of your repo, and within the Dockerfile use the
ADD command to include your source code in the container.
As you have it written now, your private key is part of the Docker image. Anyone you share the image with will also have your private key.