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

在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 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 Overflowicon-default.png?t=N7T8https://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-b7c93a8b0dbicon-default.png?t=N7T8https://medium.com/@david.limkys/permanently-create-an-ifconfig-loopback-alias-macos-b7c93a8b0db

  • 21
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值