Docker访问宿主机翻墙服务

林一二2024年09月08日 19:15
Ref: issue
Keywords:

容器里直接配

export http_proxy=http://host.docker.internal:1080

对于 DNS 污染的这样无效,需要在 protainer 的 Advanced container settings - Hosts file entries 加入:

raw.githubusercontent.com:151.101.76.133

给整个 Docker 配

C:\Users\linonetwo\.docker\config.json

{
	"auths": {
		"core.image-registry.xxxx.site": {}
	},
	"credsStore": "desktop",
	"proxies": {
		"default": {
			"httpProxy": "http://10.10.1.12:1080",
			"httpsProxy": "http://10.10.1.12:1080",
			"noProxy": "xxxx.site,localhost,127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,aliyuncs.com,.svc,.cluster.local,.ewhisper.cn"
		}
	},
	"currentContext": "default",
	"plugins": {
		"-x-cli-hints": {
			"enabled": "true"
		}
	}
}

要注意这样配的如果地址变了,就会导致容器里出现 syscall: 'connect',npm error address: '10.10.1.12', 这样的报错,而因为实际上并没有在容器里配过任何 proxy,就会比较难排查。