这是docker git命令
WORKDIR /var/www
RUN git clone --verbose git@github.com:<private git repo>.git /var/www
git clone命令执行时没有错误,但在附加到容器后,我无法在任何文件夹中找到该项目。我已经尝试在克隆之前插入/ var / www但结果相同。奇怪的是,我期望--verbose标志输出项目的摘要细节,但事实并非如此。所以我添加了一个语句来验证ssh连接:
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 clone输出:
Cloning into '/var/www'...
Warning: Permanently added the RSA host key for IP address to the list of known hosts.
我使用nsenter docker-enter连接到正在运行的容器。 / var / www为空
答案 0 :(得分:5)
我认为git clone
工作正常,但由于/var/www
是一个卷,所以更改将被丢弃。在Dockerfile
中声明卷后,您无法对该目录进行更改;记住卷在运行时设置。
如果在git clone语句之后移动VOLUME
语句,它会将文件复制到卷中。如果您不能这样做,则可以在运行时以CMD
或ENTRYPOINT
脚本执行克隆。
有关卷的详细信息,请参阅Docker官方文档https://docs.docker.com/userguide/dockervolumes/或此博客http://container-solutions.com/2014/12/understanding-volumes-docker/
答案 1 :(得分:1)
错误是测试的一部分。您正在认证GitHub。
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仓库指定了什么路径,Git默认使用该目录。可以通过提供指定要将代码放入的目录的后续参数来覆盖它(例如git clone git@github.com:UserName/someproject.git somedirectory
。
如果您对目录具有写入权限,则代码内容应该在那里。
您可以通过ls -l
验证权限,如果您是拥有/var/www
的用户所拥有或属于同一群组的用户,则该权限应该有效。
答案 2 :(得分:1)
我偶然发现错误:
ERROR: Hi [username]! You've successfully authenticated, but GitHub does not provide shell access Connection to github.com closed.
过去。
在我的情况下,它与正确设置GIT_SSH环境变量有关, 也许以下链接也会对您有所帮助:github: No supported authentication methods available
干杯。
-Ricardo