在 docker 容器内使用 SSH 密钥 [英] Using SSH keys inside docker container
问题描述
我有一个使用 Git 执行各种有趣内容的应用程序(例如运行 git clone 和 git push),我正在尝试对其进行 docker-ize.
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.
我遇到了一个问题,我需要能够将 SSH 密钥添加到容器以供容器用户"使用.
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.
我尝试将它复制到 /root/.ssh/
,更改 $HOME
,创建一个 git ssh 包装器,但仍然没有运气.
I tried copying it into /root/.ssh/
, changing $HOME
, creating a git ssh wrapper, and still no luck.
这里是 Dockerfile 供参考:
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
运行像 git pull
推荐答案
原来在使用 Ubuntu 时,ssh_config 不正确.您需要添加
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
到您的 Dockerfile 以使其识别您的 ssh 密钥.
to your Dockerfile in order to get it to recognize your ssh key.
这篇关于在 docker 容器内使用 SSH 密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!