Skip to content

Adding document on how to use HTTP/HTTPS proxy in three different scenarios #518

Closed
@docete

Description

@docete

Sometimes we need to use HTTP/HTTPS proxy in three different scenarios:

  • For dockerd

    When we want to use HTTP/HTTPS proxy for “docker pull” command, we should tell the dockerd service the proxy information, which managed by systemd. So we should change the systemd configuration for dockerd. See official documentation.

    • Create a systemd drop-in directory for the docker service
    sudo mkdir -p /etc/systemd/system/docker.service.d
    
    • Create a file named /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_PROXY environment variable:
    [Service]
    Environment="HTTP_PROXY=http://proxy.example.com:8080/"
    Environment="HTTPS_PROXY=http://proxy.example.com:8080/"
    Environment="NO_PROXY=localhost,127.0.0.1,.example.com"
    
    • Flush changes and restart Docker
    sudo systemctl daemon-reload
    sudo systemctl restart docker
    
  • For containers

    When we want to use HTTP/HTTPS proxy in docker containers, we have to choices to tell the containers the proxy information. See official documentation.

    • Configure the docker client

      • On the docker client, create or edit the file ~/.docker/config.json and add JSON similar to the following example
      {
       "proxies":
       {
         "default":
         {
           "httpProxy": "http://proxy.example.com:8080/",
           "httpsProxy": "http://proxy.example.com:8080/",
           "noProxy": "localhost,127.0.0.1,.example.com"
         }
       }
      }    
      
    • Use environment variables

      • Set the environment variables manually
      Variable docker run example
      HTTP_PROXY --env HTTP_PROXY="http://proxy.example.com:8080/"
      HTTPS_PROXY --env HTTPS_PROXY="http://proxy.example.com:8080/"
      NO_PROXY --env NO_PROXY="localhost,127.0.0.1,.example.com"
  • For build phase

    When we want to use HTTP/HTTPS proxy in build phase, we also have two choices to tell docker build client the proxy information. See official document 1 and 2

    • Use --build-arg environment variables for docker build command
    docker build \
        --build-arg "HTTP_PROXY=http://proxy.example.com:8080/" \
        --build-arg "HTTPS_PROXY=http://proxy.example.com:8080/" \
        --build-arg "NO_PROXY=localhost,127.0.0.1,.example.com" .
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions