Configuration July 28, 2026

Clash Docker Transparent Proxy: Advanced GitHub & Docker Hub Setup

This guide shows developers and DevOps engineers how Docker traffic flows through Clash and how to configure transparent routing without relying on per-container manual settings. It includes production-minded YAML and Compose examples, DNS safeguards, rule debugging, and practical fixes for registry and package-manager failures.

Docker Proxy GitHub Acceleration Advanced Config YAML

1. Scope, safety, and the Docker traffic model

This guide is for developers and DevOps engineers who already operate Clash, Mihomo, or a compatible client and need Docker workloads to use a predictable proxy path. The target scenario is not simply opening a browser through Clash. It is a host running Docker Engine, Docker Compose services, build jobs, package managers, and registry clients that must reach GitHub, Docker Hub, language package registries, or private artifact services without adding proxy variables to every container by hand.

Docker traffic can leave the machine through several different paths. A container making an outbound HTTPS request normally uses the container network namespace, its configured DNS resolver, the Docker bridge gateway, and then the host’s routing table. The Docker daemon is a separate actor: when it pulls an image, it may connect to Docker Hub before the container exists. A build process can also run in an intermediate BuildKit environment with its own network behavior. These paths look similar in a browser but are not interchangeable from Clash’s perspective.

That distinction explains a common failure pattern. You enable the system proxy in Clash, GitHub opens correctly in Chrome, and then docker pull returns a timeout or a manifest error. The browser follows the host’s application proxy settings, while Docker Engine may ignore them. Likewise, an application inside a container may resolve a registry hostname through Docker’s embedded DNS and then open a direct socket that never reaches the local mixed port. A working browser test therefore proves only one traffic path.

There are three useful designs:

For production, begin with explicit proxying to validate credentials and routing, then move to transparent interception only when the workload justifies it. Transparent mode is powerful, but it is not a magic switch: traffic generated by the Docker daemon, traffic that uses UDP or QUIC, and traffic to private networks may need separate treatment. Do not intercept corporate control planes, cloud metadata endpoints, or internal registries until their security requirements are documented.

2. Prepare Clash and Docker networking before writing rules

Start by identifying which Clash core and client are actually running. Clash Verge Rev and Mihomo clients expose different labels for TUN, redirection, mixed ports, and DNS settings, while the underlying behavior may also depend on the core version. Record the local API address, the proxy group name, the TUN status, and the listening ports before changing anything. A useful runbook entry includes the host operating system, Docker Engine version, Compose version, Clash client version, and the output of docker info.

The container must be able to reach the Clash listener. On Linux, 127.0.0.1 inside a container points to the container itself, not the host. On Docker Desktop, host.docker.internal is usually available, but native Linux installations may need an explicit host mapping. Compose can provide that mapping with the host-gateway feature:

services:
  probe:
    image: curlimages/curl:latest
    extra_hosts:
      - "host.docker.internal:host-gateway"
    environment:
      HTTPS_PROXY: http://host.docker.internal:7890
      HTTP_PROXY: http://host.docker.internal:7890
      NO_PROXY: localhost,127.0.0.1,.internal
    command: ["https://api.github.com"]

The port in this example is only illustrative. Use the port that Clash actually exposes, and make sure the listener accepts connections from the Docker bridge rather than only from loopback. Binding a proxy port to every interface without firewall rules is unsafe because other devices may use it as an open relay. Prefer a host firewall rule that allows only the Docker bridge subnet, or use a dedicated internal listener when the client supports one.

A basic Mihomo-style foundation might look like this:

mixed-port: 7890
allow-lan: true
bind-address: "*"
mode: rule
log-level: info

dns:
  enable: true
  listen: 0.0.0.0:1053
  enhanced-mode: fake-ip
  nameserver:
    - https://1.1.1.1/dns-query
    - https://dns.google/dns-query
  fake-ip-filter:
    - "*.lan"
    - "*.local"
    - "localhost"
    - "host.docker.internal"

rules:
  - DOMAIN-SUFFIX,github.com,Proxy
  - DOMAIN-SUFFIX,githubusercontent.com,Proxy
  - DOMAIN-SUFFIX,docker.io,Proxy
  - DOMAIN-SUFFIX,docker.com,Proxy
  - DOMAIN-SUFFIX,ghcr.io,Proxy
  - DOMAIN-SUFFIX,internal,DIRECT
  - IP-CIDR,10.0.0.0/8,DIRECT,no-resolve
  - IP-CIDR,172.16.0.0/12,DIRECT,no-resolve
  - IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
  - MATCH,DIRECT

Do not copy this as a universal production profile. The nameserver choices, fake-IP policy, proxy group, and private CIDR exceptions must match your organization. The important principles are that internal destinations are classified before a catch-all rule, registry hostnames are observed rather than guessed, and private addresses are not accidentally sent through a commercial relay.

3. Configure explicit proxying first, then transparent routing

3.1 Configure the Docker daemon for image pulls

Image pulls are performed by Docker Engine, not by a shell inside an already-running container. Configure the daemon separately if Docker Hub, GitHub Container Registry, or another external registry is unreachable. On a systemd-based Linux host, create a drop-in such as:

sudo mkdir -p /etc/systemd/system/docker.service.d

sudo tee /etc/systemd/system/docker.service.d/proxy.conf <<'EOF'
[Service]
Environment="HTTP_PROXY=http://127.0.0.1:7890"
Environment="HTTPS_PROXY=http://127.0.0.1:7890"
Environment="NO_PROXY=localhost,127.0.0.1,.local,.internal,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"
EOF

sudo systemctl daemon-reload
sudo systemctl restart docker

If the Clash listener is inside a desktop application or another container, replace the loopback address with a reachable host address. Then verify the daemon environment with systemctl show --property=Environment docker and test a small image pull. A successful docker pull alpine:latest confirms the daemon path, but it does not prove that application traffic inside containers is routed correctly.

3.2 Configure Compose services without hiding the network contract

For ordinary HTTP clients, Compose variables are the least surprising starting point. Use an environment file rather than committing credentials or machine-specific addresses to source control:

# .env.proxy
HTTP_PROXY=http://host.docker.internal:7890
HTTPS_PROXY=http://host.docker.internal:7890
http_proxy=http://host.docker.internal:7890
https_proxy=http://host.docker.internal:7890
NO_PROXY=localhost,127.0.0.1,postgres,redis,.internal,10.0.0.0/8
no_proxy=localhost,127.0.0.1,postgres,redis,.internal,10.0.0.0/8
services:
  worker:
    image: example/worker:stable
    extra_hosts:
      - "host.docker.internal:host-gateway"
    env_file:
      - .env.proxy

Keep uppercase and lowercase variants because different runtimes inspect different names. Go, Python, Node, Git, and package managers do not all implement proxy discovery identically. NO_PROXY is equally important: an overly broad proxy value can send database connections, service discovery, or cloud metadata requests to Clash. Test hostname forms with and without ports because some clients interpret NO_PROXY suffixes differently.

3.3 Move to transparent interception with clear boundaries

A TUN-based Clash mode can capture host traffic at the virtual interface and apply domain rules without requiring every process to understand HTTP proxies. This is often the cleanest route for containers when the client supports TUN capture of Docker bridge traffic. Enable TUN only after confirming that the client can create the required device, install routes, and handle DNS. On Linux, the Clash process may need elevated capabilities such as NET_ADMIN; granting broad privileges to an untrusted container is not an acceptable shortcut.

Transparent redirection and TUN are not identical. Redirection usually handles TCP sockets that are redirected through a listener, whereas TUN can operate at a broader IP layer and may support more protocols. Neither should be assumed to capture every Docker path. Docker’s userland proxy, bridge NAT, IPv6, rootless mode, and host firewall can change which packets are visible. Start with one disposable Compose project, inspect connections, and add production services only after the route is reproducible.

If a service uses HTTP/2 or QUIC, force a controlled TCP test before diagnosing Clash. For example, use curl --http1.1 against an HTTPS endpoint and temporarily disable QUIC in the client if supported. A successful TCP request followed by a failed UDP request indicates a protocol coverage problem rather than a bad GitHub rule. Avoid disabling TLS verification to “make the proxy work”; that hides certificate and interception problems while weakening supply-chain security.

4. Route GitHub, Docker Hub, and DNS without creating leaks

Registry access is more distributed than a single hostname suggests. Docker Hub commonly involves authentication, registry, token, CDN, and image-layer endpoints. GitHub operations may touch github.com, api.github.com, githubusercontent.com, release assets, GitHub Packages, or ghcr.io. Package managers add their own mirrors and certificate endpoints. Build a list from logs rather than treating a forum-maintained hostname list as permanent truth.

A practical discovery sequence is to run one operation at a time: authenticate to the registry, pull a small public image, pull a multi-layer image, clone a repository, download a release asset, and install one package. Record the exact hostname and whether the connection came from Docker Engine, a container, or the host. Mihomo’s connection panel and logs can show the matched rule and selected proxy group; host tools such as ss, tcpdump, and Docker daemon logs help identify traffic that never reached Clash.

Place specific rules before broad rules. A simplified example is:

rules:
  - DOMAIN,api.github.com,Proxy
  - DOMAIN,github.com,Proxy
  - DOMAIN-SUFFIX,githubusercontent.com,Proxy
  - DOMAIN-SUFFIX,githubassets.com,Proxy
  - DOMAIN,auth.docker.io,Proxy
  - DOMAIN,registry-1.docker.io,Proxy
  - DOMAIN-SUFFIX,docker.io,Proxy
  - DOMAIN-SUFFIX,docker.com,Proxy
  - DOMAIN,ghcr.io,Proxy
  - DOMAIN-SUFFIX,internal,DIRECT
  - GEOIP,LAN,DIRECT
  - MATCH,DIRECT

Do not send every domain containing “docker” through a relay without checking ownership. A private registry may be named docker.internal.example and must remain on a corporate path. Conversely, a CDN hostname may not contain “github” at all. When an image pull fails after authentication succeeds, inspect the layer download host; authentication and blob delivery frequently use different endpoints.

DNS deserves its own test plan. If Clash uses fake-IP mode, ensure Docker’s resolver path is compatible with the TUN implementation. If the container resolves the registry through Docker’s embedded resolver while the host resolves it through Clash, the returned address and routing decision may diverge. For sensitive internal names, use a fake-IP filter or nameserver policy that preserves real answers. For external names, ensure DNS requests do not escape through the host’s default resolver when your threat model requires them to follow the proxy path.

A safe debugging order is to compare four results: resolution inside the container, resolution on the host, a direct TCP connection, and a request through the Clash mixed port. Use commands such as:

docker run --rm alpine:latest getent hosts registry-1.docker.io
docker run --rm curlimages/curl:latest -I https://github.com
docker run --rm curlimages/curl:latest -x http://host.docker.internal:7890 -I https://github.com
curl -v --proxy http://127.0.0.1:7890 https://registry-1.docker.io/v2/

A registry returning 401 Unauthorized can be a healthy result: it proves that TLS and routing reached the registry, while authentication is still required. A DNS failure, connection reset, or timeout indicates a different layer. Separate network diagnosis from credential diagnosis so that changing tokens does not mask a routing defect.

5. Debug failures systematically and operate the setup safely

When transparent routing fails, reduce the problem to a known endpoint and one network namespace. First test the host through Clash, then test a minimal container through an explicit proxy, then test the same container without proxy variables while TUN or redirection is enabled. This progression tells you whether the failure is caused by container reachability, proxy protocol support, DNS handling, or interception. Do not change rules, DNS mode, and Docker firewall settings simultaneously; you will lose the causal signal.

Common symptoms have useful interpretations:

Production operation also requires controls beyond connectivity. Pin image digests for sensitive deployments, keep registry credentials in Docker secrets or an external secret manager, and never place a subscription URL or proxy password in a public Compose file. Restrict the Clash listener with host firewall rules, rotate relay credentials, and review logs for tokens, repository names, or internal hostnames. If traffic carries source code or private artifacts, verify that the selected relay and its jurisdiction meet your organization’s policy.

Keep a small health-check project in the repository. It should test one external HTTPS endpoint, one GitHub API request, one Docker Hub registry request, one internal service, and one DNS lookup. Run it after changing Clash rules, Docker Engine versions, firewall policies, or network plugins. A reproducible check is more valuable than a dashboard showing that the proxy process is merely “running.”

Compared with all-in-one VPN clients that expose only a global on/off switch, a carefully configured Clash deployment gives Docker teams observable rule matches, separate paths for GitHub and private registries, explicit DNS controls, and the option to start with environment-based proxying before adopting transparent interception. Those controls make failures easier to localize and reduce the risk of tunneling internal traffic by accident. If you need that combination for Docker Hub pulls, Git operations, and package-manager builds, the platform-specific Clash clients provide a practical next step without forcing every container to carry a custom networking script.

6. Frequently asked questions

Does configuring a proxy inside a container fix Docker image pulls?

No. Image pulls are normally performed by Docker Engine before the container starts. Configure the daemon separately, or use host-level transparent routing that captures the daemon’s connections. Container environment variables affect processes launched inside the container, not necessarily the daemon.

Why does host.docker.internal work on Docker Desktop but not on native Linux?

Docker Desktop provides this hostname as part of its virtualized networking layer. Native Linux Docker installations may require an explicit host-gateway mapping or another host address reachable from the bridge. Confirm that the Clash listener is bound to an address accessible from the container and protected by a firewall.

Is a 401 Unauthorized response from Docker Hub proof that Clash is broken?

Usually not. A 401 response often proves that the request reached the registry and that TLS negotiation completed. It indicates missing or invalid registry credentials. Timeouts, DNS errors, and connection resets are more consistent with routing, DNS, firewall, or transport problems.

Should every Docker destination go through the proxy?

No. Keep private networks, internal registries, databases, service discovery, and approved corporate endpoints on their required direct or corporate VPN paths. Use specific external rules for GitHub, Docker Hub, and observed package endpoints, then verify the result in Clash logs instead of relying on a broad catch-all rule.

Download Clash clients and start configuring Docker routing →

Ready to get started?

Use a compatible Clash or Mihomo client to inspect rules, validate DNS behavior, and build a reliable proxy path for Docker development workflows.