本文介绍了使用 Docker Compose 将主机的 SSH 密钥注入 Docker Machine的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Mac OS X 上使用 Docker 和 Docker 机器(使用默认的 boot2docker 机器),我使用 docker-compose 来设置我的开发环境.

I am using Docker on Mac OS X with Docker Machine (with the default boot2docker machine), and I use docker-compose to setup my development environment.

假设其中一个容器称为stack".现在我想做的是调用:

Let's say that one of the containers is called "stack". Now what I want to do is call:

docker-composer run stack ssh user@stackoverflow.com

我的公钥(已添加到 stackoverflow.com 并将用于验证我的身份)位于主机上.我希望此密钥可用于 Docker Machine 容器,以便我能够在容器内使用该密钥对 stackoverflow 进行身份验证.最好不要将我的密钥物理复制到 Docker Machine.

My public key (which has been added to stackoverflow.com and which will be used to authenticate me) is located on the host machine. I want this key to be available to the Docker Machine container so that I will be able to authenticate myself against stackoverflow using that key from within the container. Preferably without physically copying my key to Docker Machine.

有没有办法做到这一点?另外,如果我的密钥受密码保护,有没有办法解锁一次,这样每次注射后我就不必手动输入密码?

Is there any way to do this? Also, if my key is password protected, is there any way to unlock it once so after every injection I will not have to manually enter the password?

推荐答案

您可以将此添加到您的 docker-compose.yml(假设您在容器内的用户是 root):

You can add this to your docker-compose.yml (assuming your user inside container is root):

volumes:
    - ~/.ssh:/root/.ssh

你也可以检查更高级的ssh代理解决方案(我自己没试过)

Also you can check for more advanced solution with ssh agent (I did not tried it myself)

这篇关于使用 Docker Compose 将主机的 SSH 密钥注入 Docker Machine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 00:55