Here's the entrypoint of my Dockerfile:

ENTRYPOINT ssh-agent bash\
           && ssh-add directory/id_rsa

If I run my docker container with docker run my_conatiner -rm, I get:

Could not open a connection to your authentication agent.

instead of being prompted to insert the private key password.

If I run, however, with ENTRYPOINT /bin/bash, and paste the two commands manually, I get prompted to insert the password for the private key.


Running ssh-agent bash will start a new bash with the environment variables set. But since you don't provide any input, the bash exits, together with the ssh-agent and then in the original bash, there is again no connection to your ssh-agent. With a diagram of processes how they are called:

 '- ssh-agent bash
   '- bash < no input, exits cleanly
 '- ssh-add ...

What you want to do instead is to invoke ssh-agent the intended way:

ENTRYPOINT eval `ssh-agent` \
       && ssh-add directory/id_rsa

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.