【发布时间】:2016-08-19 01:24:54
【问题描述】:
我刚刚在 Windows 环境(Windows 7 Pro)上安装了 docker 工具箱,但由于企业代理,我遇到了网络超时。如何在 docker 工具箱中设置代理?
感谢您的帮助。
【问题讨论】:
标签: windows proxy docker-toolbox
我刚刚在 Windows 环境(Windows 7 Pro)上安装了 docker 工具箱,但由于企业代理,我遇到了网络超时。如何在 docker 工具箱中设置代理?
感谢您的帮助。
【问题讨论】:
标签: windows proxy docker-toolbox
我遇到了同样的问题。这是我的解决方案。
环境:
Win7,Docker Toolbox 17.03,cmder终端,背后企业代理设置。
解决方案:
在 C:\Program Files\Docker Toolbox 中,找到 start.sh 文件。添加以下两个代理设置:
export http_proxy="http://hostname:port/"
export https_proxy="http://hostname:port/"
至少,它对我有用。
【讨论】:
#!/bin/bash export http_proxy="http://[user]:[password]@hostname:port/" export https_proxy="http://[user]:[password]@hostname:port/"
start.sh 文件中的第一个trap ... 命令之后添加了export http_proxy="http://hostname:port/" export https_proxy="http://hostname:port/"。
我在 Windows 7 上遇到了类似的问题,但通过以下步骤解决了:
步骤 1. 使用以下配置创建批处理脚本 C:\Program Files\Docker Toolbox\kitematic_proxy.cmd
set proxy=YOUR_PROXY
SET HTTP_PROXY=%proxy%
SET HTTPS_PROXY=%proxy%
for /f %%i in ('docker-machine.exe ip default') do set DOCKER_HOST=%%i
SET NO_PROXY=%DOCKER_HOST%
set DOCKER_HOST=tcp://%DOCKER_HOST%:2376
cd Kitematic
Kitematic.exe
步骤 2. 从开始菜单打开 Oracle 虚拟机,单击 显示 进入命令提示符(确保您的 Oracle Vm 已启动并运行)
输入 sudo vi /var/lib/boot2docker/profile
添加这行
export HTTP_PROXY=http://your.proxy.name:8080
export HTTPS_PROXY=http://your.proxy.name:8080
使用您的代理地址和端口
这个链接对我帮助很大 https://github.com/docker/kitematic/wiki/Common-Proxy-Issues-&-Fixes
注意:
【讨论】:
在企业代理后面的 windows 7 (docker 18.09.0) 上安装 docker 对我来说相当复杂。以下是我遵循的步骤:
choco install docker-toolbox(警告!不要将 Docker 用于 Windows,因为它针对 Windows 10)docker-machine ls 应该为空。如果未运行:docker-machine rm default)docker-machine --native-ssh create -d virtualbox --engine-env HTTP_PROXY=$HTTP_PROXY --engine-env HTTPS_PROXY=$HTTPS_PROXY default。C:\Program Files\Docker Toolbox\start.sh
docker pull busybox。这应该可行。【讨论】:
我在安装 Windows 7 Docker 工具箱时遇到问题
$ docker --version
Docker version 18.09.3, build 774a1f4eee
$ docker-compose --version
docker-compose version 1.23.2, build 1110ad01
当我尝试时
docker run hello-world
我收到了
无法在本地找到图像“hello-world:latest” C:\Program Files\Docker Toolbox\docker.exe:来自守护程序的错误响应:获取https://registry-1.docker.io/v2/:net/http:在等待连接时取消请求(等待标头时超出了 Client.Timeout)。 请参阅“C:\Program Files\Docker Toolbox\docker.exe run --help”。
根据https://docs.docker.com/toolbox/faqs/troubleshoot/我已经在docker机器内的/var/lib/boot2docker/profile注册了我的企业代理:
使用
ssh登录虚拟机。本例登录default机器。$ docker-machine ssh default docker@default:~$ sudo vi /var/lib/boot2docker/profile
然后我在profile的末尾添加了我的企业代理
export "HTTP_PROXY=http://host:port"
export "HTTPS_PROXY=http://host:port"
然后我继续说明
将
NO_PROXY设置添加到文件末尾,类似于以下示例。export "NO_PROXY=192.168.*.*"重启 Docker。 修改 VM 上的
profile后,重新启动 Docker 并注销机器。docker@default:~$ sudo /etc/init.d/docker restart docker@default:~$ exit
之后docker run hello-world 命令运行良好
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
正如@rsb2097 提到的,每次 PC 重新启动 Docker Machine 后都会丢失 /var/lib/boot2docker/profile 中的设置。我也面临同样的问题,我不知道如何避免这种情况,但我制作了一个脚本来更简单地编写这些设置。
我认为这是因为我在没有停止 docker 机器的情况下关闭了 PC(VirtualBox 说关闭时有活动连接):假设它损坏了。
我试过docker-machine stop,但没有帮助。
因此,我编写了 AddDockerMachineProxy.cmd 脚本,该脚本使用来自 Putty (https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html) 的 plink.exe 写入代理设置。
用法
运行Docker Quickstart Terminal,我有以下输出:
Starting "default"...
(default) Check network to re-create if needed...
(default) Windows might ask for the permission to configure a dhcp server.
Sometimes, such confirmation window is minimized in the taskbar.
(default) Waiting for an IP...
Machine "default" was started.
Waiting for SSH to be available...
Detecting the provisioner...
Started machines may have new IP addresses.
You may need to re-run the `docker-machine env` command.
Regenerate TLS machine certs?
Warning: this is irreversible. (y/n): Regenerating TLS certificates
Waiting for SSH to be available...
Detecting the provisioner...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
运行AddDockerMachineProxy.cmd 脚本(plink.exe 必须在%PATH% 中):
@echo off
echo Was "Docker Quickstart Terminal" run after the reboot to init the machine?
echo If not this script fails.
pause
set "exePlink=plink.exe"
set "connectionString=-pw tcuser docker@192.168.99.100"
echo Profile BEFORE:
call "%exePlink%" %connectionString% cat /var/lib/boot2docker/profile
if errorlevel 1 ( echo ERROR: PSCP failed !!! & goto BadExit )
echo APPENDING PROXY
call "%exePlink%" %connectionString% sudo bash -c "'echo export \"HTTP_PROXY=http://host:port\">> /var/lib/boot2docker/profile'"
if errorlevel 1 ( echo ERROR: PSCP failed !!! & goto BadExit )
call "%exePlink%" %connectionString% sudo bash -c "'echo export \"HTTPS_PROXY=http://host:port\">> /var/lib/boot2docker/profile'"
if errorlevel 1 ( echo ERROR: PSCP failed !!! & goto BadExit )
call "%exePlink%" %connectionString% sudo bash -c "'echo export \"NO_PROXY=192.168.*.*\">> /var/lib/boot2docker/profile'"
if errorlevel 1 ( echo ERROR: PSCP failed !!! & goto BadExit )
echo Profile AFTER:
call "%exePlink%" %connectionString% cat /var/lib/boot2docker/profile
if errorlevel 1 ( echo ERROR: PSCP failed !!! & goto BadExit )
echo Restart docker service:
call "%exePlink%" %connectionString% sudo /etc/init.d/docker restart
if errorlevel 1 ( echo ERROR: PSCP failed !!! & goto BadExit )
echo Testing connection
call docker image pull hello-world || ( echo ERROR: docker image pull is failed !!! & goto BadExit )
echo Done!
exit /b 0
:BadExit
echo ERROR !!!
exit /b 1
【讨论】:
docker-machine stop,但没有帮助。因此,我编写了 .cmd-script,它使用来自 Putty (chiark.greenend.org.uk/~sgtatham/putty/latest.html) 的 plink.exe 编写代理设置。我将在答案中添加我的脚本。
bash 更改为 sh
啊!实际上,Docker Toolbox windows 部分只是创建虚拟机的一个非常薄的层,所以我的方法是配置虚拟机本身以使一切正常。所以。
0) 在 Windows 主机上设置全局环境变量
HTTP_PROXY = "http://login:password@yourproxy:8080"
HTTPS_PROXY = "http://login:password@yourproxy:8080"
注意大写字母! (也可以设置FTP_PROXY和NO_PROXY)
1) 运行 Docker 快速启动终端,它将在您的 VirtualBox 或其他目录下创建名为 default 的虚拟机。它还将显示您新创建的虚拟机的地址,例如
docker is configured to use the default machine with IP 192.168.99.104
2) SSH 到此地址(即使用 PuTTY)。登录:docker 密码:tcuser
3) 运行
echo '
{
"proxies":
{
"default":
{
"httpProxy": "http://login:password@yourproxy:8080",
"httpsProxy": "http://login:password@yourproxy:8080"
}
}
}' > /home/docker/.docker/config.json
这将强制 docker 客户端(在 VM 上!)运行内部具有正确环境的容器。
4) 现在你可以在 VM 中使用 docker 客户端了。要强制 Windows docker 客户端(以及 docker-compose)也在正在运行的容器中设置正确的环境,请将与第 3 页相同的 config.json 在 Windows 主机上放置到 C:\User\<yourhomedir>\.docker 目录。
现在检查运行容器内的环境
docker run -ti ubuntu env
HTTPS_PROXY=http://login:password@yourproxy:8080
https_proxy=http://login:password@yourproxy:8080
HTTP_PROXY=http://login:password@yourproxy:8080
http_proxy=http://login:password@yourproxy:8080
请注意,CAPS 和小写字母变量均已正确设置!
最后检查一切正常:
docker run -ti ubuntu apt-get update
5) 您可能面临的一个问题是您的代理地址来自网络,docker 在创建自己的网络时使用该地址,因此在您执行docker network create 之后它会破坏到您的代理的路由。因此,请确保代理地址不像 172.18.x.x 。如果是这样,通过在 VM 上进行另一个配置,强制 docker 为创建的网络使用另一个地址空间
sudo -i
echo '
{
"default-address-pools": [
{"base":"172.80.0.0/16","size":24}
]
}' > /etc/docker/daemon.json
然后重启dockerd/etc/init.d/docker restart
6) 不要重启虚拟机,需要时暂停。
【讨论】: