docker desktop for mac os如何使用本地代理

作者 : admin 本文共2538个字,预计阅读时间需要7分钟 发布时间: 2024-06-17 共1人阅读

在macbook上弄了个代理,然后按照网上所说的去配代理

docker desktop for mac os如何使用本地代理插图

然后测试下

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 or 0.0.0.0 (ie not 127.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 own localhost. Therefore, it won’t connect to the proxy server on the localhost 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:

  1. Make your proxy server listen on 0.0.0.0 instead of 127.0.0.1Caution: you’ll need proper firewall configuration to prevent malicious access to it.

  2. Add a loopback alias to the lo0 interface, e.g. 10.200.10.1/24:

     sudo ifconfig lo0 alias 10.200.10.1/24
    
  3. 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 port 8989).

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 Overflowdocker desktop for mac os如何使用本地代理插图(1)https://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






    Label
    org.my.ifconfig
    RunAtLoad
    
    ProgramArguments
    
      /sbin/ifconfig
      lo0
      alias
      YourIpHere
    

原文链接

https://medium.com/@david.limkys/permanently-create-an-ifconfig-loopback-alias-macos-b7c93a8b0dbdocker desktop for mac os如何使用本地代理插图(1)https://medium.com/@david.limkys/permanently-create-an-ifconfig-loopback-alias-macos-b7c93a8b0db

本站无任何商业行为
个人在线分享 » docker desktop for mac os如何使用本地代理
E-->