V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
lucasj
V2EX  ›  程序员

请问大佬, MacOS 下如何设置 docker 使用本地代理?

  •  
  •   lucasj · 58 天前 · 2207 次点击
    这是一个创建于 58 天前的主题,其中的信息可能已经有所发展或是发生改变。

    尝试了很多方法,依然无法拉取镜像

    $ docker pull busybox
    
    Using default tag: latest
    latest: Pulling from library/busybox
    213a27df5921: Retrying in 1 second
    error pulling image configuration: download failed after attempts=6: net/http: TLS handshake timeout
    

    方法一:设置终端代理

    export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890
    

    方法二:设置 daemon.json

    按照官方文档 Configure the daemon to use a proxy 修改 ~/.docker/daemon.json

    以上方法都不生效。

    22 条回复    2024-07-23 21:28:38 +08:00
    user100saysth
        1
    user100saysth  
       58 天前   ❤️ 1
    前几天弄过 centos7 的,供参考
    docker 配置代理------
    sudo mkdir -p /etc/systemd/system/docker.service.d
    984 sudo touch /etc/systemd/system/docker.service.d/proxy.conf
    985 vi /etc/systemd/system/docker.service.d/proxy.conf
    ```
    [Service]
    Environment="HTTP_PROXY=http://localhost:7890/"
    Environment="HTTPS_PROXY=http://localhost:7890/"
    Environment="NO_PROXY=localhost,127.0.0.1,.example.com"
    ```

    sudo systemctl daemon-reload
    sudo systemctl restart docker
    78786381
        3
    78786381  
       58 天前
    docker desktop -》 setting -》 resources -》 proxies
    78786381
        4
    78786381  
       58 天前
    zhuisui
        5
    zhuisui  
       58 天前
    修改 daemon.json 法肯定是有用的
    xubeiyan
        6
    xubeiyan  
       58 天前
    用`docker info` 看看是否设置中有
    ```
    HTTP Proxy: socks5://127.0.0.1:7890
    HTTPS Proxy: socks5://127.0.0.1:7890
    ```
    类似的项目,还有就是改了配置需要使用`systemctl restart docker`重新载入 docker
    fugu37
        7
    fugu37  
       58 天前   ❤️ 1
    因为 docker 只支持 linux ,macos 和 windows 都要用虚拟机兼容,配置方法自然和正常的 docker 不一样
    Volekingsg
        8
    Volekingsg  
       58 天前   ❤️ 1
    macOS 下面一个比较简单的方式,开个增强模式(即虚拟网关),Surge 和 Clash 一般都支持
    wnpllrzodiac
        9
    wnpllrzodiac  
       58 天前
    cf 大法岂不美哉
    wu67
        10
    wu67  
       58 天前
    最近的版本好像有 bug. 我之前一直是在 docker 设置里面设置 127+端口的. 今天更新发现这个设置失效了.
    然后把 docker 设置面板里面代理关掉, 让他自己走系统代理就好了
    beginor
        11
    beginor  
       58 天前 via Android
    Docker 在 Mac 上是虚拟机, 所以 Mac 上使用 127.0.0.1 作为代理地址是肯定不行的, 必须设置成 Mac 本机的内网 IP 地址才能使用。

    或者使用 Proxifier 来设置代理规则也行。
    Yuesh1
        13
    Yuesh1  
       58 天前   ❤️ 2
    把 127.0.0.1 改成 host.docker.internal


    127.0.0.1 访问的是 mac 的 docker 起的一个虚拟机
    Yuesh1
        14
    Yuesh1  
       58 天前
    @Yuesh1 我的意思是在 ~/.docker/daemon.json 里配置的
    tr1v1z
        15
    tr1v1z  
       58 天前 via Android
    https://docs.orbstack.dev/settings#proxy

    你用的 orbstack 吗?
    另外为啥不用 tun 模式
    zsh2517
        16
    zsh2517  
       58 天前
    @78786381 #3 补一张图

    ![]( https://imgur.com/SM5bmcT)
    leokun
        17
    leokun  
       58 天前   ❤️ 1
    tun 模式可以
    luodan
        18
    luodan  
       58 天前   ❤️ 1
    楼上说的增强模式应该是最方便的。随时开启,随时关闭。
    skuuhui
        19
    skuuhui  
       57 天前
    “按照官方文档 Configure the daemon to use a proxy 修改 ~/.docker/daemon.json”我是生效的,如果不行,那就是镜像源有问题。
    哦,你拉取的时候得 docker pull <源域名>/busybox
    zbatman
        20
    zbatman  
       57 天前 via Android
    只是拉镜像的话,用 cf workers 或者用 cf 套 nginx 自己搭建一个就行吧,cf 在国内应该还是可以访问的
    svyrblg
        21
    svyrblg  
       46 天前
    1 、通过界面设置
    docker desktop -》 setting -》 resources -》 proxies
    2 、通过配置文件设置
    "proxies": {
    "default": {
    "httpProxy": "http://127.0.0.1:20171",
    "httpsProxy": "http://127.0.0.1:20171"
    }
    },
    注意:只能使用 http 协议,socks5 不能使用。
    svyrblg
        22
    svyrblg  
       46 天前
    已经经过测试
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1588 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 00:02 · PVG 08:02 · LAX 17:02 · JFK 20:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.