Dockerfile unable to access ‘.git/‘: Failed to connect to gitlab.com

问题

在命令行手动build一个dockerfile时无法连接到git

Dockerfile中的系统和本地的不同,适用于本地的配置直接在Dockerfile中使用无效

1
2
git config --global http.proxy 'http://172.31.xx.xx:808'
git config --global https.proxy 'https://172.31.xx.xx:808'

Dockerfile中使用ifconfig命令提示

1
/bin/sh: 1: ifconfig: not found

无法找到对应的IP

解决方法

直接在本地下载好,使用COPY命令复制到Docker

注意事项

下载好的文件和Dockerfile要在同一级目录,因为COPYADD 命令不能拷贝上下文之外的本地文件

COPY命令要放在运行原来git命令的RUN命令前

1
2
3
4
5
6
7
8
9
10
11
12
COPY eigen /usr/local/src/eigen
RUN cd /usr/local/src \
# && ifconfig \
# && git config --global http.proxy 'http://172.31.70.88:808' \
# && git config --global https.proxy 'https://172.31.70.88:808' \
# && git clone https://gitlab.com/libeigen/eigen.git \
# && COPY /data/cuiyujie/lib/Spherical-Package/eigen . \
&& cd eigen \
&& mkdir build \
&& cd build \
&& cmake .. \
&& make install -j 4

否则放到其它地方会重新构建一个Docker,又要重新执行一遍前面的命令

参考

https://www.cnblogs.com/sparkdev/p/9573248.html

https://blog.csdn.net/qq_28880087/article/details/110441110


Dockerfile unable to access ‘.git/‘: Failed to connect to gitlab.com
http://yojayc.github.io/2021/09/10/Dockerfile-unable-to-access-‘-git-‘-Failed-to-connect-to-gitlab-com/
作者
Truman
发布于
2021年9月10日
更新于
2026年4月5日
许可协议