You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何让docker-compose通过Socks5代理拉取镜像?

How to Make docker-compose Pull Images via SOCKS5 Proxy

Since you already have your SOCKS5 tunnel up and running with ssh -vND 1080 user@server_ip, let's break this down into a few straightforward methods to get docker-compose using that proxy for image pulls.

Method 1: Temporary One-Off Usage (Environment Variables)

This is perfect if you only need the proxy for a single docker-compose command. Just prefix your docker-compose command with the proxy environment variables that Docker recognizes:

HTTP_PROXY=socks5://localhost:1080 HTTPS_PROXY=socks5://localhost:1080 docker-compose pull

If you have internal registries or domains you don't want to route through the proxy, add the NO_PROXY variable too:

HTTP_PROXY=socks5://localhost:1080 HTTPS_PROXY=socks5://localhost:1080 NO_PROXY=localhost,127.0.0.1,your-internal-registry.local docker-compose pull

Method 2: Global Docker Daemon Configuration (Permanent Setup)

If you want all docker commands (including docker-compose) to use the SOCKS5 proxy by default, you can configure the Docker daemon directly:

On Linux:

  1. Create or edit the daemon configuration file at /etc/docker/daemon.json:

    {
      "proxies": {
        "default": {
          "httpProxy": "socks5://localhost:1080",
          "httpsProxy": "socks5://localhost:1080",
          "noProxy": "localhost,127.0.0.1,localaddress,.localdomain.com"
        }
      }
    }
    

    Adjust the noProxy list to include any domains/IPs you want to bypass the proxy for.

  2. Restart the Docker daemon to apply changes:

    sudo systemctl restart docker
    

On Docker Desktop (Windows/macOS):

  1. Open Docker Desktop settings, navigate to the Resources > Proxies tab.
  2. Select "Manual proxy configuration".
  3. Enter socks5://localhost:1080 for both HTTP and HTTPS proxy fields.
  4. Add your bypass domains to the "No proxy" field, then click "Apply & Restart".

Once set up, any docker-compose pull or docker-compose up command will automatically use your SOCKS5 proxy for image pulls.

Important Notes

  • Make sure your SSH tunnel (ssh -vND 1080 user@server_ip) stays active when running docker-compose commands—if the tunnel drops, the proxy will fail.
  • These settings apply to the Docker daemon's image pulling process, not to the containers themselves. If you need containers to use the proxy, you'll need to add proxy environment variables directly to your docker-compose.yml service definitions.

内容的提问来源于stack exchange,提问作者Phoenix

火山引擎 最新活动