如何配置Docker容器代理? [英] How to configure docker container proxy?

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

问题描述

我是Docker的新手。我尝试为debian:jessie图像设置代理,但我没有成功。我遵循此



我的代理服务器: http:// username:password @ proxy2.domain.com

解决方案

您可以在启动时设置代理环境变量容器,例如:

  docker容器运行\ 
-e HTTP_PROXY = http://用户名: password@proxy2.domain.com \
-e HTTPS_PROXY = http:// username:password@proxy2.domain.com \
myimage

如果希望在启动容器时自动使用代理服务器,则可以在Docker CLI配置文件中配置默认​​代理服务器(〜/ .docker / config.json )。您可以在网络连接部分中找到有关此操作的说明。 在用户指南中。



例如:

  {
代理:{
默认:{
httpProxy: http://用户名:password@proxy2.domain.com,
httpsProxy : http:// username:password@proxy2.domain.com
}
}
}

要验证〜/ .docker / config.json 配置是否正常工作,请启动一个容器并打印其 env

  docker container run --rm busybox env 

PATH = / usr / local / sbin:/ usr / local / bin:/ usr / sbin:/ usr / bin:/ sbin:/ bin
HOSTNAME = 220e4df13604
HTTP_PROXY = http://用户名:password@proxy2.domain.com
http_proxy = http://用户名:password@proxy2.domain.com
HTTPS_PROXY = http://用户名:password@proxy2.domain.com
https_proxy = http:/ /username:password@proxy2.domain.com
HOME = / root


I am newbie for docker. I try set a proxy for debian:jessie image but i didnt make it. I follow this link . I apply all of them with cat tag (example: 'cat > proxy.sh' , because vi or another editor not installed ) but there is some error about my proxy in apt-get update command.

Error Photo

My proxy : http://username:password@proxy2.domain.com

解决方案

You can set the proxy environment variables when starting the container, for example:

docker container run \
  -e HTTP_PROXY=http://username:password@proxy2.domain.com \
  -e HTTPS_PROXY=http://username:password@proxy2.domain.com \
  myimage

If you want the proxy-server to be automatically used when starting a container, you can configure default proxy-servers in the Docker CLI configuration file (~/.docker/config.json). You can find instructions for this in the networking section in the user guide.

For example:

{
  "proxies": {
    "default": {
      "httpProxy": "http://username:password@proxy2.domain.com",
      "httpsProxy": "http://username:password@proxy2.domain.com"
    }
  }
}

To verify if the ~/.docker/config.json configuration is working, start a container and print its env:

docker container run --rm busybox env

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=220e4df13604
HTTP_PROXY=http://username:password@proxy2.domain.com
http_proxy=http://username:password@proxy2.domain.com
HTTPS_PROXY=http://username:password@proxy2.domain.com
https_proxy=http://username:password@proxy2.domain.com
HOME=/root

这篇关于如何配置Docker容器代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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