dockergit克隆在生成过程中不克隆(而不是错误)

这是docker git命令

WORKDIR /var/www RUN git clone --verbose git@github.com:<private git repo>.git /var/www 

git clone命令执行时没有错误,但在连接到容器后,我无法在任何文件夹中find项目。 我已经尝试cd到/ var / www克隆之前,但结果相同。 有一件奇怪的事情,我希望–verbose标志输出项目的摘要细节,但不是。 所以我添加了一个声明来validationSSH连接:

  RUN \ chmod 600 /repo-key && \ echo "IdentityFile /repo-key" >> /etc/ssh/ssh_config && \ echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config && \ ssh -v git@github.com 

它连接成功,输出:

  Hi willlopez! You've successfully authenticated, but GitHub does not provide shell access. debug1: channel 0: free: client-session, nchannels 1 debug1: fd 0 clearing O_NONBLOCK debug1: fd 1 clearing O_NONBLOCK debug1: fd 2 clearing O_NONBLOCK Transferred: sent 2944, received 1464 bytes, in 0.1 seconds Bytes per second: sent 31103.1, received 15467.0 debug1: Exit status 1 

git克隆输出:

  Cloning into '/var/www'... Warning: Permanently added the RSA host key for IP address to the list of known hosts. 

我用nsenterdockerinput附加到正在运行的容器。 / var / www是空的

我认为git clone工作正常,但作为/var/www是一个卷,更改被扔掉。 在Dockerfile声明一个卷后,不能更改该目录; 记得在运行时build立卷。

如果在git clone语句之后移动VOLUME语句,它会将文件复制到卷中。 如果你不能这样做,你可以在运行时在CMDENTRYPOINT脚本中执行克隆。

有关卷的更多信息,请参阅官方Docker文档https://docs.docker.com/userguide/dockervolumes/或此博客http://container-solutions.com/2014/12/understanding-volumes-docker/

错误是testing的一部分。 你正在向GitHubvalidation。

 Hi MakotoTheKnight! You've successfully authenticated, but GitHub does not provide shell access. debug1: client_input_channel_req: channel 0 rtype exit-status reply 0 debug1: channel 0: free: client-session, nchannels 1 Connection to github.com closed. Transferred: sent 3632, received 1800 bytes, in 0.1 seconds Bytes per second: sent 27200.9, received 13480.6 debug1: Exit status 1 

也就是说,每当你做git clone ,无论你为私有的Git仓库指定了什么path,Git默认使用这个目录。 可以通过提供一个后续参数指定要放置代码的目录来覆盖它(例如, git clone git@github.com:UserName/someproject.git somedirectory

如果你有写权限到目录,你的代码内容应该在那里。 您可以通过ls -l来validation权限,如果您是拥有/var/www的用户所在的用户,或者属于同一个用户组,则应该可以正常工作。

我也偶然发现了这个错误:

 ERROR: Hi [username]! You've successfully authenticated, but GitHub does not provide shell access Connection to github.com closed. 

以往。

在我的情况下,它涉及到正确设置GIT_SSH环境variables,也许下面的链接也会帮助你: github:没有支持的身份validation方法可用

干杯。

-Ricardo