Docker Ubuntu背后的代理 [英] Docker Ubuntu Behind Proxy

查看:81
本文介绍了Docker Ubuntu背后的代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看文档时,没有关于如何在代理后面运行它的说明。
https://docs.docker.com/installation/ubuntulinux/

Looking at docs there is no instruction on how to run it behind a proxy. https://docs.docker.com/installation/ubuntulinux/

在论坛上阅读,指示是更新/ etc / default / docker以导出代理设置。

Reading on forums, the instruction is to update /etc/default/docker to export the proxy setup.

 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

Then we restart/start docker

 sudo service docker start

在容器内,如果我运行 apt-get,npm install,bower install,我将无法通过代理。

Inside a container, if I run 'apt-get', npm install, bower install I cant get through the proxy.

不确定我缺少什么。

推荐答案

Ubuntu 14.04 LTS



对于使用 SysVinit Ubuntu 14.04 LTS ,您应修改 / etc / default / docker 文件:

Ubuntu 14.04 LTS

For Ubuntu 14.04 LTS who uses SysVinit, you should modify /etc/default/docker file:

# 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/"
......

然后重新启动 docker

service docker restart



Ubuntu 16.04 LTS / Ubuntu 18.04 LTS



对于 Ubuntu 16.04 LTS 使用 Systemd 的用户,您可以按照以下 post

Ubuntu 16.04 LTS / Ubuntu 18.04 LTS

For Ubuntu 16.04 LTS who uses Systemd, you can follow this post:

(1)创建系统的插入目录:

(1) Create a systemd drop-in directory:

mkdir /etc/systemd/system/docker.service.d

(2)在 /etc/systemd/system/docker.service.d/http-proxy.conf 文件中添加代理:

(2) Add proxy in /etc/systemd/system/docker.service.d/http-proxy.conf file:

# 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:

(4) Restart Docker:

systemctl restart docker

官方参考

这篇关于Docker Ubuntu背后的代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆