Using ssh-agent with docker on macOS

后端 未结 8 2124
不思量自难忘°
不思量自难忘° 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:27

    Socket forwarding doesn't work on OS X yet. Here is a variation of @henrjk answer brought into 2019 using Docker for Mac instead of boot2docker which is now obsolete.

    1. First run a ssh server in the container, with /tmp being on the exportable volume. Like this

       docker run -v tmp:/tmp -v \
       ${HOME}/.ssh/id_rsa.pub:/root/.ssh/authorized_keys:ro \
       -d -p 2222:22 arvindr226/alpine-ssh
      
    2. Then ssh into this container with agent forwarding

       ssh -A -p 2222 root@localhost
      
    3. Inside of that ssh session find out the current socket for ssh-agent

       3f53fa1f5452:~# echo $SSH_AUTH_SOCK
       /tmp/ssh-9zjJcSa3DM/agent.7
      
    4. Now you can run your real container. Just make sure to replace the value of SSH_AUTH_SOCK below, with the value you got in the step above

       docker run -it -v tmp:/tmp  \
       -e SSH_AUTH_SOCK=/tmp/ssh-9zjJcSa3DM/agent.7 \
       vladistan/ansible
      

提交回复
热议问题