使用 dockerfile 克隆私有 git 仓库 [英] Clone private git repo with dockerfile

查看:27
本文介绍了使用 dockerfile 克隆私有 git 仓库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从似乎是各种工作 dockerfiles 的地方复制了这段代码,这是我的:

I have copied this code from what seems to be various working dockerfiles around, here is mine:

FROM ubuntu

MAINTAINER Luke Crooks "luke@pumalo.org"

# Update aptitude with new repo
RUN apt-get update

# Install software 
RUN apt-get install -y git python-virtualenv

# Make ssh dir
RUN mkdir /root/.ssh/

# Copy over private key, and set permissions
ADD id_rsa /root/.ssh/id_rsa
RUN chmod 700 /root/.ssh/id_rsa
RUN chown -R root:root /root/.ssh

# Create known_hosts
RUN touch /root/.ssh/known_hosts

# Remove host checking
RUN echo "Host bitbucket.org
	StrictHostKeyChecking no
" >> /root/.ssh/config

# Clone the conf files into the docker container
RUN git clone git@bitbucket.org:Pumalo/docker-conf.git /home/docker-conf

这给了我错误

Step 10 : RUN git clone git@bitbucket.org:Pumalo/docker-conf.git /home/docker-conf
 ---> Running in 0d244d812a54
Cloning into '/home/docker-conf'...
Warning: Permanently added 'bitbucket.org,131.103.20.167' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
2014/04/30 16:07:28 The command [/bin/sh -c git clone git@bitbucket.org:Pumalo/docker-conf.git /home/docker-conf] returned a non-zero code: 128

这是我第一次使用 dockerfiles,但从我读过的(和从工作配置中获取的)我看不出为什么这不起作用.

This is my first time using dockerfiles, but from what I have read (and taken from working configs) I cannot see why this doesn't work.

我的 id_rsa 与我的 dockerfile 位于同一个文件夹中,并且是我本地密钥的副本,它可以毫无问题地克隆这个 repo.

My id_rsa is in the same folder as my dockerfile and is a copy of my local key which can clone this repo no problem.

在我的 dockerfile 中,我可以添加:

In my dockerfile I can add:

RUN cat /root/.ssh/id_rsa

它打印出正确的密钥,所以我知道它被正确复制了.

And it prints out the correct key, so I know its being copied correctly.

我也试着按照诺亚的建议去做,然后跑了:

I have also tried to do as noah advised and ran:

RUN echo "Host bitbucket.org
	IdentityFile /root/.ssh/id_rsa
	StrictHostKeyChecking no" >> /etc/ssh/ssh_config

遗憾的是,这也不起作用.

This sadly also doesn't work.

推荐答案

我的密钥受密码保护导致了这个问题,下面列出了一个工作文件(以帮助未来的 googlers)

My key was password protected which was causing the problem, a working file is now listed below (for help of future googlers)

FROM ubuntu

MAINTAINER Luke Crooks "luke@pumalo.org"

# Update aptitude with new repo
RUN apt-get update

# Install software 
RUN apt-get install -y git
# Make ssh dir
RUN mkdir /root/.ssh/

# Copy over private key, and set permissions
# Warning! Anyone who gets their hands on this image will be able
# to retrieve this private key file from the corresponding image layer
ADD id_rsa /root/.ssh/id_rsa

# Create known_hosts
RUN touch /root/.ssh/known_hosts
# Add bitbuckets key
RUN ssh-keyscan bitbucket.org >> /root/.ssh/known_hosts

# Clone the conf files into the docker container
RUN git clone git@bitbucket.org:User/repo.git

这篇关于使用 dockerfile 克隆私有 git 仓库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆