国内Linux 使用 http 代理,愉快使用 docker wget curl git apt

  • 在使用 docker build 打包镜像时,遇到了需要使用代理访问网络的需求。使用如下的 Dockerfile 来模拟这个场景:

    FROM golang
    RUN curl www.google.com --max-time 3
  • 国内一般网络环境下,curl www.google.com 是无法正常返回的,加入 --max-time 让 curl 的耗时不要太长。

http.png

我们知道Linux系统添加Http代理,可以使用如下命令,使用http代理支持的软件多一些

export http_proxy="http://192.168.1.135:8010"
export https_proxy="http://192.168.1.135:8010"

curl google.com

现在把命令行改写成 http.sh 脚本,使用: . http.sh [ip:port]

# usage:  . http.sh [ip:port]

http_proxy=http://192.168.1.135:8010

if [[ $# > 0 ]]; then
  http_proxy=http://$1
fi
echo "export https_proxy=${http_proxy}"

export http_proxy=$http_proxy
export https_proxy=$http_proxy
curl google.com

怎么才能有这个IP地址呢,如图 V2N 客户端 config.json

V2.png

或者使用 socks5tohttp 转换成 http 代理

brook.png

分类: linux学习资源

0 条评论

发表回复

Avatar placeholder

您的电子邮箱地址不会被公开。 必填项已用 * 标注

© 2024 兰雅VBA代码分享
浙ICP备2021017795号-2 浙公网安备33078102100266号