I've mounted the ~/.ssh directory into my development docker container from the host machine and trying to add the deployment key to the ssh agent in the entrypoint like this:
#!/bin/bash
set -e
#add the deployment key
if [[ ! -z ${DEPLOYMENT_SSH_KEY} ]] ; then
echo "Adding deployment ssh key ${DEPLOYMENT_SSH_KEY} to ssh agent"
eval $(ssh-agent -s) && ssh-add /.ssh/${DEPLOYMENT_SSH_KEY}
else
echo "Deployment ssh key is not defined"
fi
echo "STARTING PHP FPM, CMD $@"
docker-php-entrypoint "$@"
The key gets normally added according to the logs:
Agent pid 8
Adding deployment ssh key id_rsa to ssh agent
Identity added: /.ssh/id_rsa (rsa w/o comment)
However, it actually ends up with no keys added to the agent and I can't clone my repos from inside the container. The command ssh-add -l executed in the container says
Could not open a connection to your authentication agent.
Why's that? I heard of the SSH agent forwarding as an alternative but I'm wondering why the method I've tried doesn't work?