代理背后的Docker Ubuntu
查看文档时,没有关于如何在代理后运行它的说明。 在论坛上阅读,说明是更新/etc/default/docker以导出代理设置代理背后的Docker Ubuntu,docker,Docker,查看文档时,没有关于如何在代理后运行它的说明。 在论坛上阅读,说明是更新/etc/default/docker以导出代理设置 export http_proxy="http://127.0.0.1:3128/" export https_proxy="http://127.0.0.1:3128/" export HTTP_PROXY="http://127.0.0.1:3128/" export HTTPS_PROXY="http://127.0.0.1:3128/" 然后我们重启/
export http_proxy="http://127.0.0.1:3128/"
export https_proxy="http://127.0.0.1:3128/"
export HTTP_PROXY="http://127.0.0.1:3128/"
export HTTPS_PROXY="http://127.0.0.1:3128/"
然后我们重启/启动docker
sudo service docker start
在容器中,如果运行“apt-get”、npm-install、bower-install,则无法通过代理
不确定我遗漏了什么。您应该将
127.0.0.1
替换为您的主机IP或Ubuntu 14.04.2 LTS的一些公共可访问IP
Linux vagrant-ubuntu-trusty-64 3.13.0-54-generic\91 ubuntu SMP周二5月26日19:15:08 UTC 2015 x86\u 64 x86\u 64 GNU/Linux
编辑您的/etc/default/docker
文件
sudo vim /etc/default/docker
在底部添加此行:
export http_proxy="http://PROXY_IP:PROXY_PORT"
重新启动docker
服务
sudo service docker restart
Ubuntu 14.04 LTS
对于使用SysVinit
的ubuntu14.04 LTS
,您应该修改/etc/default/docker
文件:
# cat /etc/default/docker
# Docker Upstart and SysVinit configuration file
#
# THIS FILE DOES NOT APPLY TO SYSTEMD
#
# Please see the documentation for "systemd drop-ins":
# https://docs.docker.com/engine/articles/systemd/
#
.......
# If you need Docker to use an HTTP proxy, it can also be specified here.
export http_proxy="http://web-proxy.corp.xxxxxx.com:8080/"
export https_proxy="https://web-proxy.corp.xxxxxx.com:8080/"
......
# cat /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=https://web-proxy.corp.xxxxxx.com:8080/"
Environment="HTTPS_PROXY=https://web-proxy.corp.xxxxxx.com:8080/"
Environment="NO_PROXY=localhost,127.0.0.1,localaddress,.localdomain.com"
然后重新启动docker:
service docker restart
Ubuntu 16.04 LTS/Ubuntu 18.04 LTS
对于使用Systemd
的ubuntu16.04lts
,您可以遵循以下步骤:
(1) 创建systemd下拉式目录:
mkdir /etc/systemd/system/docker.service.d
(2) 在/etc/systemd/system/docker.service.d/http proxy.conf
文件中添加代理:
# cat /etc/default/docker
# Docker Upstart and SysVinit configuration file
#
# THIS FILE DOES NOT APPLY TO SYSTEMD
#
# Please see the documentation for "systemd drop-ins":
# https://docs.docker.com/engine/articles/systemd/
#
.......
# If you need Docker to use an HTTP proxy, it can also be specified here.
export http_proxy="http://web-proxy.corp.xxxxxx.com:8080/"
export https_proxy="https://web-proxy.corp.xxxxxx.com:8080/"
......
# cat /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=https://web-proxy.corp.xxxxxx.com:8080/"
Environment="HTTPS_PROXY=https://web-proxy.corp.xxxxxx.com:8080/"
Environment="NO_PROXY=localhost,127.0.0.1,localaddress,.localdomain.com"
(3) 刷新更改:
systemctl daemon-reload
(4) 重新启动Docker:
systemctl restart docker
必须安装systemctl,这可能会有问题。
如果/etc/systemd/system/docker.service.d/http-proxy.conf或/etc/default/docker解决方案不适用于您,只需使用以下命令:
docker build[OPTIONS]路径--build arg http\u代理=http://your.proxy:port --构建arg https\u代理=http://your.proxy:port --build arg no_proxy=.internal.domain,localhost,127.0.0.1
在Ubuntu 14.04 LTS中:
关于HTTP_代理,HTTPS_代理的一个有趣的问题是:如果您的密码有一个特殊的字符,如“$”、“%”,那么当您执行命令(如:dock run xxx)时,docker守护进程将无法正确处理它,您将遇到错误。然后您可以尝试将特殊字符设置为其他字符,祝您好运。根据
添加到~/.docker/config.json
代理配置
{
"proxies":
{
"default":
{
"httpProxy": "http://127.0.0.1:3001",
"noProxy": "*.test.example.com,.example2.com"
}
}
}
您可以尝试在/etc/environment
中添加行:
https_proxy="http://127.0.0.1:3128"
http_proxy="http://127.0.0.1:3128"
ftp_proxy="http://127.0.0.1:3128"
no_proxy="127.0.0.1/8, localhost, 192.168.0.0/16"
它对于Linux系统上的所有服务都很有用
然后编辑/lib/systemd/system/docker.service
。
在[Service]
部分的末尾,添加以下行:
EnvironmentFile=/etc/environment
然后:
sudo systemctl daemon-reload
sudo systemctl restart docker.service
容器内部127.0.0.1
将指向容器本身。这里可能不是你想要的IP。对于未来的读者来说,在问题中澄清什么样的代理和目的是有帮助的。因为在反向代理后面运行docker实例是很常见的,而且OP想要实现什么并不十分明显。也许:“我希望能够执行来自docker容器的HTTP请求,但需要通过web代理”。检查此链接,它已经非常清楚地指定了所有可能的方式:像一个符咒一样工作!也为我工作!Ubuntu17.04中的路径是/lib/systemd/system/docker.service拉取图像时出错:Gethttps://index.docker.io/v1/repositories/library/mongo/images: http:连接到代理服务器时出错https://proxy-foo.com:80: 拨打127.0.1.1:53上的tcp:lookup proxy-foo.com:没有这样的主机
,我在16.04上收到了这个错误非常好!经过大量的搜索,这个成功了!其他网站通常只提供Ubuntu 14的配置。我最喜欢这种方法。但是,在重新启动服务之前,我必须运行“systemctl daemon reload”