Using ssh-agent with docker on macOS

后端 未结 8 2126
不思量自难忘°
不思量自难忘° 2021-02-02 10:18

I would like to use ssh-agent to forward my keys into the docker image and pull from a private github repo.

I am using a slightly modified version of https://github.com/

8条回答
  •  粉色の甜心
    2021-02-02 10:29

    I ran into a similar issue, and was able to make things pretty seamless by using ssh in master mode with a control socket and wrapping it all in a script like this:

    #!/bin/sh   
    
    ssh -i ~/.vagrant.d/insecure_private_key -p 2222 -A -M -S ssh.socket -f docker@127.0.0.1 tail -f /dev/null
    
    HOST_SSH_AUTH_SOCK=$(ssh -S ssh.socket docker@127.0.0.1 env | grep "SSH_AUTH_SOCK" | cut -f 2 -d =)
    
    docker run -v $HOST_SSH_AUTH_SOCK:/ssh-agent \
           -e "SSH_AUTH_SOCK=/ssh-agent" \
           -t hello-world "$@"
    
    ssh -S ssh.socket -O exit docker@127.0.0.1
    

    Not the prettiest thing in the universe, but much better than manually keeping an SSH session open IMO.

提交回复
热议问题