The problem is when you have a setup like this on your local machine you have an access to the terminal for SSH adding the key to the known_hosts asking
The authenticity of host 'server-name (***)' can't be established.
RSA key fingerprint is XXXXXXX.
Are you sure you want to continue connecting (yes/no)?
and you can basically interact, and type yes and ssh-agent add the connection to the known_hosts for you. However, in this case the things happen inside a docker container, and you basically cannot interect with this prompt. The solution for this is to add StrictHostKeyChecking no flag to ssh config, there are several ways to do it for git command, and you can check them here.
So basically, the following is the elegant way to solve this, just make .ssh/config file and add the ssh options we want.
eval $(ssh-agent) > /dev/null
# add the ssh key
ssh-add /root/.ssh/id_rsa
kill $SSH_AGENT_PID
echo "Host bitbucket.org" > /root/.ssh/config
echo "User git" >> /root/.ssh/config
echo "IdentityFile /root/.ssh/id_rsa" >> /root/.ssh/config
echo "StrictHostKeyChecking no" >> /root/.ssh/config
git clone ssh://[email protected]/project/repo.git
StrictHostKeyChecking no option just discards the prompt and directly adds the connection to the known_hosts, and basically afterwards can git clone.