问题描述
跟进 How to configure docker container proxy?
我在将 localhost 代理传递到 docker 容器时遇到问题:
$ curl --proxy socks5://localhost:18888 https://goolge.ca
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
docker run -ti -p 18888:18888 ...
# within docker
$ curl --proxy socks5://localhost:18888 https://goolge.ca
curl: (7) Failed to connect to localhost port 18888: Connection refused
$ curl --proxy https://localhost:18888 https://goolge.ca
curl: (7) Failed to connect to localhost port 18888: Connection refused
$ curl --proxy http://localhost:18888 https://goolge.ca
curl: (7) Failed to connect to localhost port 18888: Connection refused
$ curl --proxy socks5://0.0.0.0:18888 https://goolge.ca
curl: (7) Failed to connect to 0.0.0.0 port 18888: Connection refused
- 这是在 macOS 下。
- 我也尝试从 docker cli 传递
--net=host
,但结果是一样的。
我错过了什么?
解决方法
如果你在 docker 容器的 bash 中运行命令,那么你应该使用
#within docker
$ curl --proxy socks5://0.0.0.0:18888 https://goolge.ca