AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1251157
Accepted
WiGeeky
WiGeeky
Asked: 2020-06-18 02:12:29 +0800 CST2020-06-18 02:12:29 +0800 CST 2020-06-18 02:12:29 +0800 CST

如何在 Ubuntu 中将 Docker 与 socks5 一起使用?

  • 772

我一直在尝试通过本地 socks5 代理运行 docker,我尝试将环境变量设置为:

export ALL_PROXY=127.0.0.1:1080

但这并没有什么区别,就好像 Docker 没有阅读它一样,我也尝试将配置放入~/.docker/config.json:

{
 "proxies":
 {
   "default":
   {
     "httpProxy": "socks5://127.0.0.1:1080"
   }
 }
}

但这也不起作用。有什么问题,如何在 Ubuntu 上使用 socks5 代理运行 Docker?

systemd proxy docker
  • 2 2 个回答
  • 3834 Views

2 个回答

  • Voted
  1. Best Answer
    WiGeeky
    2020-06-18T02:12:29+08:002020-06-18T02:12:29+08:00

    通过后来的一些研究,我找到了答案,Ubuntu 中的 docker 服务与用户的环境变量无关,但如果将其传递给 docker 服务本身,它就可以工作。

    我通过在/lib/systemd/system/docker.service文件中添加以下行来使其工作,就在之前ExecStart:

    Environment="ALL_PROXY=socks5://127.0.0.1:1080"
    

    所以我的 docker.service 文件看起来像这样:

    [Unit]
    Description=Docker Application Container Engine
    Documentation=https://docs.docker.com
    BindsTo=containerd.service
    After=network-online.target firewalld.service containerd.service
    Wants=network-online.target
    Requires=docker.socket
    
    [Service]
    Type=notify
    # the default is not to use systemd for cgroups because the delegate issues still
    # exists and systemd currently does not support the cgroup feature set required
    # for containers run by docker
    Environment="ALL_PROXY=socks5://127.0.0.1:1080"
    ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
    ExecReload=/bin/kill -s HUP $MAINPID
    TimeoutSec=0
    RestartSec=2
    Restart=always
    
    # Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
    # Both the old, and new location are accepted by systemd 229 and up, so using the old location
    # to make them work for either version of systemd.
    StartLimitBurst=3
    
    # Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
    # Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
    # this option work for either version of systemd.
    StartLimitInterval=60s
    
    # Having non-zero Limit*s causes performance problems due to accounting overhead
    # in the kernel. We recommend using cgroups to do container-local accounting.
    LimitNOFILE=infinity
    LimitNPROC=infinity
    LimitCORE=infinity
    
    # Comment TasksMax if your systemd version does not support it.
    # Only systemd 226 and above support this option.
    TasksMax=infinity
    
    # set delegate yes so that systemd does not reset the cgroups of docker containers
    Delegate=yes
    
    # kill only the docker process, not all processes in the cgroup
    KillMode=process
    
    [Install]
    WantedBy=multi-user.target
    

    这似乎已经为我解决了这个问题,它正在 Ubuntu 20.04 上运行。我认为将其张贴在这里可能会在将来对其他人有所帮助。

    • 4
  2. Neveroldmilk
    2020-08-11T19:26:07+08:002020-08-11T19:26:07+08:00

    另一种解决方案是使用privoxy并将其转发到您的 socks5 代理,以便您可以使用 privoxy 作为 https/http 代理。

    • 1

相关问题

  • 未应用网络代理

  • 自动保存特定 URL 的代理

  • 为什么应用系统范围的网络代理设置只影响超级用户(root)?[关闭]

  • 如何检查是否真的应用了网络代理?

  • 命令列出启动时启动的服务?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve