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

问题描述

我在Mac OS X和Docker Machine(默认的boot2docker计算机)上使用Docker,并使用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.

假设其中一个容器称为 堆栈。现在我想做的就是调用:

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