Linux Dockerfile build时请求超时的问题解决
Linux服务器上,使用Dockerfile build镜像拉取各种依赖时, 总会碰到因为要请求被墙的网址导致build error, 辣么怎么解决呢, 本文提供一整套问题解决方案。解决方案将包括v2ray的server与client的搭建和使用, Linux代理请求以及最后实现Dockerfile打包镜像时可以翻墙。
前言
因为最近服务都是在centos7.4上部署, 在其他版本上的差异性自己解决, 我这里给思路和一个反正的范例。
解决方案将包括v2ray的server与client的搭建和使用, Linux代理请求以及最后实现Dockerfile打包镜像时可以翻墙。
Centos v2ray的server与client的搭建和使用
v2ray server的搭建
|
|
在server端, config.json配置重点在inbounds。
/etc/localtime:/etc/localtime:ro是同步时区到容器内, 如果在确定客户端与服务端的配置参数相同的情况下,还是请求不通, 那大概率是容器里的系统时间与你客户端的时间不同造成的。
-p即是宿主机与容器的端口映射, 8888是宿主机端口,80是容器端口, 要保证宿主机的8888端口可以访问。
v2ray client的搭建
|
|
Linux代理设置
在Linux中,没有一种代理配置是配置后可以一劳永逸的,目前碰到三个代理配置, 分别对应如下
- Linux的代理配置
- 在.bashrc或者.zshrc等其他shell中配置, 大部分宿主机的请求都会走代理
- 通过proxychains强制没有走代理的软件走代理
- docker build镜像时, 以上两个都不起作用,
- 需要在.docker中做配置才可以
- 在.docker配置了代理后, 拉取的依赖有时会执行git, 如果文件很大,也会timeout, 这时就需要再dockerfile中强制git config
·以下是详细的配置, 结合上面的说明应该能明白, 不能明白就谷歌·。 如果你是想解决docker build镜像的问题, 那就不用做宿主机的配置, 直接看《docker走代理》
宿主机设置
Shell中配置,以bash为例
|
|
proxychains的安装与使用
|
|
proxychains安装如果出现问题,请自行谷歌。
docker走代理
在宿主机执行
|
|
宿主机的IP就是docker0网卡的inet, 可以ifconfig查看, 也可以执行下面的命令查看
|
|
如果在Dockerfile中有依赖需要git pull或者git submodule超时了,如图:
在Dockerfile中添加
|
|