Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
docete opened this issue Jan 13, 2023 · 2 comments · Fixed by #519
Closed

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

docete opened this issue Jan 13, 2023 · 2 comments · Fixed by #519

Comments

@docete
Copy link
Contributor

docete commented Jan 13, 2023

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" .
    
@docete
Copy link
Contributor Author

docete commented Jan 13, 2023

@yeasy 最近在公司一个项目中遇到众所周知的网络问题,查询官方文档后发现docker的各个场景下使用 HTTP/HTTPS 代理存在一些细微的差别。这部分内容并没有收录到 docker_practice 中。我大致总结了3个场景,基本覆盖了 docker 使用过程中需要设置代理的各种情况。如你有空,请帮忙 review 一下。我建议在 [高级网络设置] 一节,或者 [附录一:常见问题总结] 一节中加入相关内容。如果你没有其它意见,我将创建相应的PR提交相关内容。

@yeasy
Copy link
Owner

yeasy commented Jan 13, 2023

欢迎提交PR. @docete

yeasy added a commit that referenced this issue Jan 17, 2023
Add docs of using HTTP/HTTPS proxy

Close #518
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants