Как я могу использовать Docker с socks5 в Ubuntu?

Я пытался запустить Docker через локальный прокси-сервер socks5, я попытался установить переменную среды следующим образом:

export ALL_PROXY=127.0.0.1:1080

] Но это не имело значения, как будто Docker не читал его, я также попытался поместить конфигурацию в ~ / .docker / config.json :

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

Но это тоже не работает. В чем проблема и как я могу запустить Docker с прокси socks5 в Ubuntu?

0
задан 17 June 2020 в 13:12

2 ответа

С некоторыми исследованиями позже я нашел ответ, что докерская служба в Ubuntu не зависит от переменных среды пользователя, но если он должен быть передан в саму службу докера, он работает.

Я получил его, добавив следующую строку в файл /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. Я думал, что размещение здесь может помочь другим в будущем.

0
ответ дан 19 June 2020 в 21:23

Другое решение — использовать privoxy и вперед его к прокси-серверу socks5, чтобы вы могли использовать privoxy в качестве прокси-сервера https/http.

1
ответ дан 11 August 2020 в 03:26

Другие вопросы по тегам:

Похожие вопросы: