using docker with proxy

  1. Create the drop-in directory:
    bash
    sudo mkdir -p /etc/systemd/system/docker.service.d
    
    Use code with caution.
  2. Create the proxy configuration file:
    Create a file named /etc/systemd/system/docker.service.d/http-proxy.conf.
  3. Add your proxy details:
    Paste the following into the file, replacing the placeholder URLs with your actual proxy address:
    ini
    [Service]
    Environment="HTTP_PROXY=http://proxy.example.com:3128"
    Environment="HTTPS_PROXY=http://example.com"
    Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.example.com"
    
    Use code with caution.
  4. Apply the changes:
    Reload the systemd manager configuration and restart the Docker service:
    bash
    sudo systemctl daemon-reload
    sudo systemctl restart docker
    
    Use code with caution.
  5. Verify the configuration:
    Check if the environment variables are active:
    bash
    sudo systemctl show --property=Environment docker
    
    Use code with caution.
2. Configure the Docker Client (Containers & Builds)
This configuration tells Docker to automatically inject proxy environment variables into any new container you run or any image you build.
  1. Edit the user config file:
    Open (or create) ~/.docker/config.json in your home directory.
  2. Add the proxies block:
    Ensure the structure looks like this:
    json
    {
      "proxies": {
        "default": {
          "httpProxy": "http://proxy.example.com:3128",
          "httpsProxy": "http://example.com",
          "noProxy": "localhost,127.0.0.1"
        }
      }
    }
    
    Use code with caution.

Comments