在macbook上弄了个代理,然后按照网上所说的去配代理
然后测试下
docker pull busybox
结果无反应,超时。我去!!!
鼓捣了半天,看了docker官网,问了chatgpt ,按照它们所说的试了下也没用,最后还是在stackoverflow上找到关键信息, thank stackoverflow, 真的是技术宝库
Why a locally-bound proxy doesn't work
The Problem
If you're running a locally-bound proxy, e.g. listening on
127.0.0.1:8989
, it WON'T WORK in Docker for Mac. From the Docker documentation:I want to connect from a container to a service on the host
The Mac has a changing IP address (or none if you have no network access). Our current recommendation is to attach an unused IP to the
lo0
interface on the Mac; for example:sudo ifconfig lo0 alias 10.200.10.1/24
, and make sure that your service is listening on this address or0.0.0.0
(ie not127.0.0.1
). Then containers can connect to this address.The similar is for Docker server side. (To understand the server side and client side of Docker, try to run
docker version
.) And the server side runs on a virtualization layer which has its ownlocalhost
. Therefore, it won't connect to the proxy server on thelocalhost
of the host OS.The solution
So, if you're using a locally-bound proxy like me, basically you would have to do the following things to make it work with Docker for Mac:
Make your proxy server listen on
0.0.0.0
instead of127.0.0.1
. Caution: you'll need proper firewall configuration to prevent malicious access to it.Add a loopback alias to the
lo0
interface, e.g.10.200.10.1/24
:sudo ifconfig lo0 alias 10.200.10.1/24
Set HTTP and/or HTTPS proxy to
10.200.10.1:8989
from Preferences in Docker tray menu (assume that the proxy server is listening on port8989
).After that, test the proxy settings by running a command in a new container from an image which is not downloaded:
$ docker rmi -f hello-world ... $ docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world c04b14da8d14: Pull complete Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9 Status: Downloaded newer image for hello-world:latest ...
Notice: the loopback alias set by
ifconfig
does not preserve after a reboot. To make it persistent is another topic. Please check this blog post in Japanese (Google Translate may help).Share
原文链接
Cannot download Docker images behind a proxy - Stack Overflowhttps://stackoverflow.com/questions/23111631/cannot-download-docker-images-behind-a-proxy/41544629#41544629
按照帖子的方法,把代理地址设成了10.200.20.1,再试下,成功了,爽!
另外提到这个设置lo0的别名方式再重启电脑后就会消失。
接着就找找怎么持久化这个配置的办法
Just create a new launch demon file and configure it like so:
sudo vi /Library/LaunchDaemons/org.my.ifconfig.plist <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>org.my.ifconfig</string> <key>RunAtLoad</key> <true/> <key>ProgramArguments</key> <array> <string>/sbin/ifconfig</string> <string>lo0</string> <string>alias</string> <string>YourIpHere</string> </array> </dict> </plist>
原文链接
https://medium.com/@david.limkys/permanently-create-an-ifconfig-loopback-alias-macos-b7c93a8b0dbhttps://medium.com/@david.limkys/permanently-create-an-ifconfig-loopback-alias-macos-b7c93a8b0db