docker-公司代理后面的机器

docker-machine behind corporate proxy

我正在尝试使用 docker-machine 在企业 http 代理后面的私有云 (Openstack) 上创建一个实例。

是否可以告诉 docker-machine 使用代理,或者我是否需要一个已经用 http_proxy 环境变量预先配置的 glance 图像?

对于当前的 docker 机器版本,我找不到更好的方法来进行更改,如 boot2docker ()

如果在docker机器上手动设置/var/lib/boot2docker/profile代理,重启后,代理设置会自动移除。

所以我必须创建一个 docker 机器,并为代理

设置 --engine-env
docker-machine create -d virtualbox \
    --engine-env HTTP_PROXY=http://example.com:8080 \
    --engine-env HTTPS_PROXY=https://example.com:8080 \
    --engine-env NO_PROXY=example2.com \
    proxybox

备注:

This is a two-years-old answer, there are a lot of changes happened in docker, so if you still can't make it work behind the proxy, please read and others.

文档:create docker machine

可以修改现有的 docker- 机器配置以添加代理环境。 $HOME/.docker/machine/machines//.config.json中的config.json可以编辑。

将 "HTTP_PROXY=http://example.com:8080" 添加到 config.json 中的 Env。重启机器,一切就绪。

如前所述,您可以在

编辑文件
$HOME\.docker\machine\machines\default\config.json

并设置 HTTP_PROXY、HTTPS_PROXY 和 NO_PROXY 变量(或删除它们):

 "HostOptions": {
        "Driver": "",
        ...
        "EngineOptions": {
           ...
            "Env": [
              "HTTP_PROXY=http://10.121.8.110:8080",
              "HTTPS_PROXY=http://10.121.8.110:8080",
              "NO_PROXY=192.168.23.4"
            ],

文件编辑完成后,您只需执行:

docker-machine provision 

如果您已经创建了机器 (VM),您可以像这样配置代理:

1- SSH into the docker dev host: docker-machine ssh dev
2- Add the following lines to /var/lib/boot2docker/profile (this file is read-only, use sudo)
    export HTTP_PROXY=http://<proxy>:<port>
    export HTTPS_PROXY=http://<proxy>:<port>
3- Exit the ssh session and restart the docker machine: docker-machine restart dev 

Source

从 Docker 18.09 开始,我们可以在命令行上指定环境变量,例如容器的代理,如下所示:

docker run --env HTTP_PROXY="172.10.13.14" -it myImage:latest /bin/bash

此外,我们可以将这些设置指定给 docker 客户端,方法是将它们写入 ~/.docker/config.json 文件,如下所示:

{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://127.0.0.1:3001",
     "noProxy": "*.test.example.com,.example2.com"
   }
 }
}

可在 docs 上获得更多信息。