简体   繁体   English

如何将私有 SSH 密钥挂载到 Docker for Windows 容器?

[英]How to mount private SSH key to Docker for Windows container?

Good day everyone.今天是个好日子。

I have following dev environment:我有以下开发环境:

  • Win 10 host赢10主机
  • Docker Desktop for Windows latest适用于 Windows 的 Docker 桌面最新版
  • php5.6 image running in container via docker-compose通过 docker-compose 在容器中运行的 php5.6 图像

How can I mount my private SSH key to this container?如何将我的私有 SSH 密钥挂载到这个容器? Or is there any possibility to tunnel Pageant from host machine to container?或者是否有可能将 Pageant 从主机隧道传输到容器?

All I want is to run Capifony deploy procedures in my container.我想要的只是在我的容器中运行 Capifony 部署程序。

You could use a volume with -v /c/Users/<user>/.ssh/id_rsa:/<home dir>/.ssh/id_rsa:ro .您可以使用带有-v /c/Users/<user>/.ssh/id_rsa:/<home dir>/.ssh/id_rsa:ro home is ~ of the user eg /root , / , /home/<user> . home 是用户的~例如/root , / , /home/<user> The :ro will make it readonly, so your key will not be overwritten by accident. :ro将使其成为只读,因此您的密钥不会被意外覆盖。

The permissions on key mapped into the container will be too broad but piping the key into ssh-add bypasses this:映射到容器中的密钥的权限太宽泛,但将密钥通过管道传输到 ssh-add 绕过了这一点:

cat ~/.ssh/id_rsa | ssh-add -

Depending on your container, ssh-agent may not be already running:根据您的容器,ssh-agent 可能尚未运行:

eval `ssh-agent` 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM