Docker 代理配置

Docker pull #

文件/etc/docker/daemon.json
{
    "proxies": {
        "http-proxy": "http://127.0.0.1:7897",
        "https-proxy": "http://127.0.0.1:7897",
        "no-proxy": "localhost,127.0.0.1"
    }
}

此配置只作用于 dockerd ,详见 Daemon proxy configuration

容器内代理(containerd) 由 ~/.docker/config.json 配置,详见 Use a proxy server with the Docker CLI

Docker build #

文件dockerfile
ARG http_proxy="http://127.0.0.1:7897"
ARG https_proxy="http://127.0.0.1:7897"

构建时必须指定网络 --network host(默认网络是 bridge)。