How to set proxy in docker toolbox?
Asked Answered
R

5

19

I have just installed docker toolbox on windows environnement (Windows 7 Pro) and I have got a network time out due to the entreprise proxy. How can I set the proxy in docker toolbox ?

Thanks for your help.

Requisition answered 25/4, 2016 at 14:58 Comment(0)
C
26

I encountered the same problem. Here is my solution.

Env:

Win7, Docker Toolbox 17.03, cmder terminal, behind enterprise proxy setting.

Solution:

in C:\Program Files\Docker Toolbox, find start.sh file. add following two proxy settings:

export http_proxy="http://hostname:port/"
export https_proxy="http://hostname:port/"

At least, it works for me.

Coterie answered 18/4, 2017 at 1:32 Comment(2)
It worked for me as well, thanks :). Just to add a bit more information, if you have to provision a user and a password to your proxy you should provide them in the following manner: #!/bin/bash export http_proxy="http://[user]:[password]@hostname:port/" export https_proxy="http://[user]:[password]@hostname:port/"Tarshatarshish
Thankyou. I added export http_proxy="http://hostname:port/" export https_proxy="http://hostname:port/" after the first trap ... command in the start.sh file.Sob
E
7

I have a similar problem for Windows 7 but it was resolved by these steps :

  • Step 1. Create a batch script C:\Program Files\Docker Toolbox\kitematic_proxy.cmd with below configuration

    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
    
  • Step 2. Open Oracle Virtual machine from the start menu , go to command prompt by clicking Show (Make sure your Oracle Vm is up and running)

enter image description here

enter sudo vi /var/lib/boot2docker/profile

add this lines

export HTTP_PROXY=http://your.proxy.name:8080
export HTTPS_PROXY=http://your.proxy.name:8080

use your proxy address & port

this link help me a lot https://github.com/docker/kitematic/wiki/Common-Proxy-Issues-&-Fixes

Note:

  1. Don't forget to add 192.168.99.100 ip to your proxy setting's exception list (use inetcpl.cpl )
  2. Don't forget to add HTTP_PROXY and HTTPS_PROXY to your user variable (Advance settings->Environment variables)
  3. Don't forget to restart your pc
Elmiraelmo answered 26/1, 2017 at 11:26 Comment(0)
O
3

Installing docker on windows 7 (docker 18.09.0) behind an enterprise proxy was quite complicated for me. Here are the steps I followed:

  1. set HTTP_PROXY variable in your windows environment (HTTP_PROXY=http://your_proxy:port)
  2. install docker toolbox with installer or run in powershell as admin: choco install docker-toolbox (Warning! Don't use Docker for windows, as it targets Windows 10)
  3. ensure you don't have any previous VM created by your previous attempts ( docker-machine ls should be empty. If not run: docker-machine rm default)
  4. run in powershell as user: docker-machine --native-ssh create -d virtualbox --engine-env HTTP_PROXY=$HTTP_PROXY --engine-env HTTPS_PROXY=$HTTPS_PROXY default.
  5. run C:\Program Files\Docker Toolbox\start.sh
  6. Now run docker pull busybox. This should work.
Overstate answered 26/11, 2018 at 10:18 Comment(0)
S
1

I had an issue on my Windows 7 Docker toolbox installation

$ docker --version
Docker version 18.09.3, build 774a1f4eee

$ docker-compose --version
docker-compose version 1.23.2, build  1110ad01

When I tried

docker run hello-world

I received

Unable to find image 'hello-world:latest' locally C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while waiting headers). See 'C:\Program Files\Docker Toolbox\docker.exe run --help'.

According to https://docs.docker.com/toolbox/faqs/troubleshoot/ I've registered my enterprise proxy in /var/lib/boot2docker/profile inside the docker machine:

  1. Use ssh to log in to the virtual machine. This example logs in to the default machine.

    $ docker-machine ssh default
    docker@default:~$ sudo vi /var/lib/boot2docker/profile
    

Then I added my enterprise proxy in the end of the profile

export "HTTP_PROXY=http://host:port"
export "HTTPS_PROXY=http://host:port"

after that I continued the instructions

  1. Add a NO_PROXY setting to the end of the file similar to the example below.

      export "NO_PROXY=192.168.*.*"
    
  2. Restart Docker. After you modify the profile on your VM, restart Docker and log out of the machine.

      docker@default:~$ sudo /etc/init.d/docker restart
      docker@default:~$ exit
    

After that docker run hello-world command works well

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/

Configuration lost after PC restart

As @rsb2097 mentioned after every PC reboot Docker Machine lose the settings in /var/lib/boot2docker/profile. I face the same problem too and I don't know how to avoid this, but I made a script to write these settings simpler.

I thought that happens because I shut down the PC without stopping the docker machine (VirtualBox says that there are active connections on shut down): supposed that it damages. I tried docker-machine stop but it doesn't help.

As a result I wrote AddDockerMachineProxy.cmd script that writes the proxy settings using plink.exe from Putty (https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html).

Usage

  1. Restart the PC.
  2. Run Docker Quickstart Terminal, I have following output:

    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...
    
  3. Run AddDockerMachineProxy.cmd script (plink.exe must be in %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 [email protected]"
    
    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
    
Slippage answered 24/4, 2019 at 7:57 Comment(3)
It works for me, but configuration is lost after I restart my PC.Barcus
@rsb2097, yes, I'm losing the configuration after every PC restart too. I thought that's because I shut down the PC without stopping the docker machine (VirtualBox says that there are active connections on shut down). I tried docker-machine stop but it doesn't help. As a result I wrote .cmd-script that writes the proxy settings using plink.exe from Putty (chiark.greenend.org.uk/~sgtatham/putty/latest.html). I will add my script in the answer.Slippage
It works for me too but I had to change the shell from bash to shSalubrious
R
0

Ah! Actually with Docker Toolbox windows part is just very thin layer over created virtual machine, so my method is to configure virtual machine itself to make everything work. So.

0) Set global environment variables on Windows host machine

HTTP_PROXY = "http://login:password@yourproxy:8080"
HTTPS_PROXY = "http://login:password@yourproxy:8080"

Note caps letters! (also you can set FTP_PROXY and NO_PROXY)

1) Run Docker Quickstart Terminal, it will create virtual machine named default under you VirtualBox or whatever. Also it will display address of your newly created VM like

docker is configured to use the default machine with IP 192.168.99.104

2) SSH to this address (i.e. with PuTTY). Login:docker Password:tcuser

3) Run

echo '
{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://login:password@yourproxy:8080",
     "httpsProxy": "http://login:password@yourproxy:8080"
   }
 }
}' > /home/docker/.docker/config.json

This will force docker client (on VM!) to run containers with correct envs inside.

4) So now you can use docker client inside VM. To force Windows docker client (as well as docker-compose) also to set correct envs inside running containers, put the same config.json as in p.3 on Windows host machine to C:\User\<yourhomedir>\.docker directory.

Now check the environment inside running container

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

Note both CAPS and lower letter variables are set properly!

Final check for everything is ok:

docker run -ti ubuntu apt-get update

5) One issue you may face, is that address of your proxy is from network, which docker use when creating own networks, so it will spoil route to your proxy right after you will do docker network create. So make sure the proxy address is not like 172.18.x.x . If so force docker to use another address space for created networks by making another config on VM

sudo -i
echo '
{
  "default-address-pools": [
    {"base":"172.80.0.0/16","size":24}
  ]
}' > /etc/docker/daemon.json

Then restart dockerd /etc/init.d/docker restart

6) Do not restart your virtual machine, pause it when needed.

Rivkarivkah answered 22/3, 2019 at 19:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.