In short: How can I set the HTTP/HTTPS proxies for Docker on Mac OS X?
In detail:
I run Docker (1.12) on Mac OS X behind a proxy. I followed the installation instructions and installed boot2docker. This is working fine if I pull from my network-internal Docker registry.
However, I get the following error when pulling from docker.io:
machine:~ me$ docker run ubuntu echo hello world
Unable to find image 'ubuntu' locally
Pulling repository ubuntu
2014/06/30 13:23:26 Get https://index.docker.io/v1/repositories/ubuntu/images:
dial tcp: lookup index.docker.io: no such host
Note 1: DOCKER_HOST
, http_proxy
and https_proxy
are available in the environment (running env
displays all three).
Note 2: I read in other posts that this error occurs when the daemon is not running properly. However, docker version
doesn't show any problems. Moreover, I can pull and run images pulled from my network-internal Docker registry.
Note 3: I was able to set up Docker on Red Hat Linux (RHEL). I had to add the proxy information to /etc/sysconfig/docker
. I read that there is a similar file on Ubuntu (/etc/init/docker.conf
). However, I could not find that file for Docker (or boot2docker?) on Mac OS X.
To solve the problem with curl in docker build, I added the following inside the Dockerfile:
Note that the ENV statement is BEFORE the RUN statement.
and in order to make the docker daemon able to access the internet (I use kitematic with boot2docker), I added the following into /var/lib/boot2docker/profile :
The config files you need to modify won't be on your OS X file system, they'll be attached to the Tiny Core Linux VM which acts as your local Docker server.
To configure the proxy for that, first start Boot2docker from Applications. Once it's started, get a terminal window and ssh into the VM:
Now create/modify /var/lib/boot2docker/profile to set proxy info:
Tinycore needs the proxy info as follows: protocol://ip:port
To be safe I set proxies for both HTTP and HTTPS.
Now you can restart the VM docker service and exit the VM.
You should be able to run the client against the VM instance now.
This change is persisted through VM restarts. You should only need to do it once.
For the record, VirtualBox has a global preference setting for proxies but nothing I tried there would work.
As of the recent (August 2015) 1.8 release, docker's recommended way to create docker hosts - including boot2docker VMs - is through its docker-machine utility.
And also since version 1.8, docker-machine now supports the configuration of the proxies at VM creation time via an invocation like the following:
This results in a VM that has the specified environment variables already added to the initialization file /var/lib/boot2docker/profile - no need to manually add them anymore.
I solved this problem by setting proxy config in .profile file:
add your proxy at the end:
finally, restart your Boot2Docker.
If you are using Docker for Mac and are behind a proxy environment.
Click on the docker icon on top menu bar. (like shown in step 1.3 here )
Go to
Preferences > Advanced
and set the proxy in HTTP and HTTPS options there. Click Apply and Restart below it. You are good to go. :)The config file in boot2docker should be
/var/lib/boot2docker/profile
, edit this file to custom http(s) proxy.