在docker容器内使用SSH密钥 [英] Using SSH keys inside docker container
问题描述
我遇到一个问题,但我需要在容器中添加一个SSH密钥才能使用该容器。
有没有办法做到这一点?我尝试将它复制到/root/.ssh/中,更改$ HOME,创建一个git ssh包装器,但仍然没有运气。
以下是Docker文件供参考:
#DOCKER-VERSION ubuntu中的0.3.4
:$ 12
运行apt-get update
运行apt-get install python-software-properties python g ++ make git-core openssh- server -y
RUN add-apt-repository ppa:chris-lea / node.js
RUN echodeb http://archive.ubuntu.com/ubuntu precise universe>> /etc/apt/sources.list
运行apt-get update
运行apt-get install nodejs -y
添加。 / src
ADD ../../home/ubuntu/.ssh/id_rsa /root/.ssh/id_rsa
RUN cd / src; npm安装
EXPOSE 808:808
CMD [node,/src/app.js]
app.js
运行git命令,如 git pull
使用Ubuntu时,ssh_config不正确。您需要添加
运行echoIdentityFile〜/ .ssh / id_rsa>> / etc / ssh / ssh_config
到您的Docker文件,以使其识别您的ssh密钥。 / p>
Alright, so essentially I have an app that executes various fun stuff with Git (like running git clone & git push) and I'm trying to docker-ize it.
I'm running into an issue though where I need to be able to add an SSH key to the container for the container 'user' to use.
Is there a good way to do this? I tried copying it into /root/.ssh/, changing $HOME, creating a git ssh wrapper, and still no luck.
Here is the Dockerfile for reference:
#DOCKER-VERSION 0.3.4
from ubuntu:12.04
RUN apt-get update
RUN apt-get install python-software-properties python g++ make git-core openssh-server -y
RUN add-apt-repository ppa:chris-lea/node.js
RUN echo "deb http://archive.ubuntu.com/ubuntu precise universe" >> /etc/apt/sources.list
RUN apt-get update
RUN apt-get install nodejs -y
ADD . /src
ADD ../../home/ubuntu/.ssh/id_rsa /root/.ssh/id_rsa
RUN cd /src; npm install
EXPOSE 808:808
CMD [ "node", "/src/app.js"]
app.js
runs the git commands like git pull
Turns out when using Ubuntu, the ssh_config isn't correct. You need to add
RUN echo " IdentityFile ~/.ssh/id_rsa" >> /etc/ssh/ssh_config
to your Dockerfile in order to get it to recognize your ssh key.
这篇关于在docker容器内使用SSH密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!