如何配置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. 参考:

https://docs.docker.com/network/proxy/

posted @ 2020-05-06 10:38  Jello  阅读(4129)  评论(0编辑  收藏  举报