这是docker git命令
WORKDIR /var/www
RUN git clone --verbose git@github.com:<private git repo>.git /var/www
git clone命令执行没有错误,但是附加到容器后,在任何文件夹中都找不到该项目。我试图在克隆之前将CD插入/ 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为空
最佳答案
我认为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/。
关于git - 构建期间的docker git clone未克隆(并且未出错),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27641091/