如何配置docker使用代理?
有两种方法可选,
1. 修改docker的客户端配置文件~/.docker/config.json
$ cat ~/.docker/config.json
{
"proxies":
{
"default":
{
"httpProxy": "http://user:password@your-proxy-server:port",
"httpsProxy": "http://user:password@your-proxy-server:port",
"noProxy":
"*.test.example.com,.example2.com"
}
}
}
2. 运行docker时使用环境变量
环境变量 | Dockerfile示例 | docker run 示例 |
---|---|---|
HTTP_PROXY |
ENV HTTP_PROXY "http://user:password@your-proxy-server:port" |
--env HTTP_PROXY="http://user:password@your-proxy-server:port" |
HTTPS_PROXY |
ENV HTTPS_PROXY "http://user:password@your-proxy-server:port" |
--env HTTPS_PROXY="http://user:password@your-proxy-server:port" |
FTP_PROXY |
ENV FTP_PROXY "http://user:password@your-proxy-server:port" |
--env FTP_PROXY="http://user:password@your-proxy-server:port" |
NO_PROXY |
ENV NO_PROXY "*.test.example.com,.example2.com" |
--env NO_PROXY="*.test.example.com,.example2.com" |
3. 参考: