小编典典

在Docker容器中使用SSH密钥

docker

我有一个应用程序可以使用Git执行各种有趣的操作(例如运行git clone和git push),而我正在尝试对其进行docker-ize。

我遇到了一个问题,尽管我需要能够向容器中添加SSH密钥以供容器“用户”使用。

我尝试将其复制到/root/.ssh/,进行更改$HOME,创建了一个git ssh包装器,但还是没有运气。

这是Dockerfile供参考:

#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命令,如 git pull


阅读 672

收藏
2020-06-17

共1个答案

小编典典

原来使用Ubuntu时,ssh_config不正确。您需要添加

RUN  echo "    IdentityFile ~/.ssh/id_rsa" >> /etc/ssh/ssh_config

到您的Dockerfile,以使其能够识别您的ssh密钥。

2020-06-17