Configuring Docker Daemon Proxy Settings | Generated by AI

Home 2025.10

Configuring Docker Daemon for Proxy Settings

The Docker daemon can be configured to use an HTTP/HTTPS proxy for operations like pulling images or building containers from behind a corporate firewall. This is done by editing (or creating) the /etc/docker/daemon.json file. Note that this configuration applies to the daemon itself (e.g., for docker pull or docker build), not to individual containers (which would use environment variables or Docker build args).

Prerequisites

Step-by-Step Configuration

  1. Locate or Create the Daemon Configuration File:
    • Open a terminal and navigate to /etc/docker/ (create the directory if it doesn’t exist: sudo mkdir -p /etc/docker).
    • Edit the file daemon.json using a text editor (e.g., sudo nano /etc/docker/daemon.json or sudo vim /etc/docker/daemon.json).
    • If the file doesn’t exist, create it. Start with an empty JSON object {} if it’s new.
  2. Add Proxy Configuration:
    • Add a "proxies" section to the JSON file. Here’s a basic example:

      {
        "proxies": {
          "http-proxy": "http://proxy.company.com:8080",
          "https-proxy": "http://proxy.company.com:8080",
          "no-proxy": "localhost,127.0.0.1,*.company.com,10.0.0.0/8"
        }
      }
      
      • Explanations:
        • "http-proxy": The URL for HTTP proxy (required for non-HTTPS requests).
        • "https-proxy": The URL for HTTPS proxy (often the same as HTTP proxy).
        • "no-proxy": A comma-separated list of hosts/domains/IP ranges that should bypass the proxy (e.g., local addresses or internal domains). This prevents infinite loops.
        • If authentication is needed, use the format http://username:password@proxy.company.com:8080.
        • For SOCKS proxies, use "http-proxy": "socks5://proxy.company.com:1080".
      • If daemon.json already has existing content (e.g., other settings like "log-driver": "json-file"), merge the "proxies" section into it without duplicating keys. Ensure valid JSON syntax (use a tool like jsonlint to validate if needed).
  3. Save and Restart the Docker Daemon:
    • Save the file.
    • Restart the Docker service to apply changes:
      sudo systemctl restart docker
      
      • On older systems or non-systemd setups, use sudo service docker restart.
    • Verify the daemon is running:
      sudo systemctl status docker
      
      • Check logs if there are issues: sudo journalctl -u docker.service.
  4. Verify the Configuration:
    • Test by pulling an image (which should now route through your proxy):
      docker pull hello-world
      
    • Check if the proxy settings are applied by inspecting the daemon config:
      docker info | grep -i proxy
      
      • You should see output like:
        HTTP Proxy: http://proxy.company.com:8080
        HTTPS Proxy: http://proxy.company.com:8080
        No Proxy: localhost,127.0.0.1,*.company.com,10.0.0.0/8
        
    • If you’re using Docker in a build context, test with:
      docker build -t test-proxy .
      

      (Assuming a simple Dockerfile that pulls a base image.)

Additional Notes

For more details, refer to the official Docker docs: Configure the Docker daemon. If you encounter errors, share the exact output for troubleshooting!


Back

x-ai/grok-4-fast

Donate