Docker proxy

date
Aug 21, 2025
slug
docker-proxy
status
Published
tags
Environment
Dev
summary
type
Post
Tag
docker.io 访问受限需要配置 proxy,直接配置环境变量无法使用,需做以下处理

docker pull 阶段

  • sudo mkdir /etc/systemd/system/docker.service.d
sudo vi /etc/systemd/system/docker.service.d/http-proxy.conf
注意最后的 /
[Service]
 # NO_PROXY is optional and can be removed if not needed
 # Change proxy_url to your proxy IP or FQDN and proxy_port to your proxy port
 # For Proxy servers that require username and password authentication, just add the proper username and password to the URL. (see example below)

 # Example without authentication
 Environment="HTTP_PROXY=socks5://localhost:7891/"
 Environment="HTTPS_PROXY=socks5://localhost:7891/"
 Environment="ALL_PROXY=socks5://localhost:7891/" 

 # exclusions
 Environment="NO_PROXY=localhost,127.0.0.0/8,*.DOMAIN_TO_BYPASS"
配置生效,重启
  • sudo systemctl daemon-reload; sudo systemctl restart docker
 

docker run 运行阶段

vi ~/.docker/config.json
 {
  "proxies":
  {
    "default":
    {
      "httpProxy": "socks5://localhost:7891/",
      "httpsProxy": "socks5://localhost:7891/",
      "allProxy": "socks5://localhost:7891/",
      "noProxy": "localhost,127.0.0.1,.example.com,.xxx.com.cn,.xxx.com"
    }
  }
 }
 

result

docker compose 包含了 pull & run
notion image
 
Note.
方便 sudo 用户直接操作 docker,可配置用户组
sudo usermod -aG docker $USER
Warning.
若存在离线部署或例外,dify 需要在 "NO_PROXY=xxx 部分补充域名/IP
 
 

© Quinn Xen 2022 - 2025