Skip to main content
To set up a proxy for Docker, you need to configure the Docker Daemon and the Docker Client to use the proxy server. This is particularly useful in environments where direct internet access is restricted. You will need to configure two components:
  • Docker Client — sets proxy environment variables for containers started by the Docker CLI.
  • Docker Daemon — sets proxy environment variables for the Docker service itself (for pulling images, etc.).
1
Configure the Docker Client
2
Create or modify the config.json file located in the Docker configuration directory (~/.docker/ on Linux/macOS, or %USERPROFILE%\.docker\ on Windows).
3
The following configuration sets proxy environment variables for Docker containers started by the Docker CLI but does not configure proxy settings for the Docker Daemon itself.
4
{
  "proxies": {
    "default": {
      "httpProxy": "http://your-proxy-server:port",
      "httpsProxy": "http://your-proxy-server:port",
      "noProxy": "localhost,.local,127.0.0.1,.example.org,*.yourdomain.com"
    }
  }
}
5
If you don’t want to configure the proxy globally in config.json, you can set it inline when running or building containers:
docker build --build-arg HTTP_PROXY=http://your-proxy-server:port .
docker run -e HTTP_PROXY=http://your-proxy-server:port <image>
6
Do not use ENV in a Dockerfile to set proxy variables — it will bake the proxy settings into the image, which is typically undesirable.
7
After saving the file, verify the proxy is applied to new containers:
8
docker run <image> sh -c 'env | grep -i _proxy'

# You should see output similar to:
# http_proxy=http://your-proxy-server:port
# https_proxy=http://your-proxy-server:port
# no_proxy=localhost,.local,127.0.0.1,.example.org,*.yourdomain.com
9
Configure the Docker Daemon
10
If you want to pull images or interact with registries through a proxy, configure the Docker Daemon. On Linux, Docker Daemon runs as a systemd service.
11
  • Create a directory for Docker service overrides:
    sudo mkdir -p /etc/systemd/system/docker.service.d
    
  • Create a proxy configuration file:
    /etc/systemd/system/docker.service.d/http-proxy.conf
    [Service]
    Environment="HTTP_PROXY=http://your-proxy-server:port"
    Environment="HTTPS_PROXY=http://your-proxy-server:port"
    Environment="NO_PROXY=localhost,.local,127.0.0.1,.example.org,*.yourdomain.com"
    
  • Reload the systemd daemon and restart Docker:
    sudo systemctl daemon-reload
    sudo systemctl restart docker
    
  • Verify the proxy settings are applied to the Docker Daemon:
    sudo systemctl show --property=Environment docker
    
  • 12
    You can also set proxy settings in /etc/docker/daemon.json, though using systemd overrides is the more common approach:
    /etc/docker/daemon.json
    {
      "proxies": {
        "http-proxy": "http://your-proxy-server:port",
        "https-proxy": "http://your-proxy-server:port",
        "no-proxy": "localhost,.local,127.0.0.1,.example.org,*.yourdomain.com"
      }
    }
    
    After modifying the file, restart the Docker service:
    sudo systemctl restart docker
    

    Build docs developers (and LLMs) love