Docker Proxy
Docker代理设置
一般代理
为了更方便地上传下载,通常我们会在本机开一个HTTP协议的代理,这种情况下设置http_proxy和https_proxy到http://localhost:1081即可(我喜欢Socks代理设为1080,而Http代理设为1081,当然根据个人喜好设置)
在VSCODE设置代理
一般只有Git会用到,所以只需在settings.json文件中添加如下即可,其中操作系统要根据实际情况更换。
"terminal.integrated.env.windows": {
"http_proxy":"http://localhost:1081",
"https_proxy":"http://localhost:1081"
}
在Docker中使用代理
一般情况下只有在build时才需使用代理,因此添加
--build-arg http_proxy=http://host.docker.internal:1081 --build-arg https_proxy=http://host.docker.internal:1081
即可,注意从Docker访问宿主机不能使用localhost而要使用host.docker.internal。
使用镜像
通常,除了访问GitHub必须使用代理,下载包都可以配置镜像网站访问。 常用的一些办法是:
-
Node.js的包可以在npm install时加上--registry https://registry.npm.taobao.org(默认为https://registry.npmjs.org),或者使用cnpm,或nrm。 -
Python可以在pip3 install时指定--index-url https://pypi.tuna.tsinghua.edu.cn/simple(默认为https://pypi.org/simple),或者在全局设置pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple。