Skip to content

Instantly share code, notes, and snippets.

@paulccarey
Forked from josiah14/osx-install-and-proxy.md
Last active September 9, 2015 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulccarey/629c812345f93e4665ab to your computer and use it in GitHub Desktop.
Save paulccarey/629c812345f93e4665ab to your computer and use it in GitHub Desktop.
OSX Installation and Proxy configuration

The setup for getting docker working on OSX behind a proxy is slightly more complex than just following the instructions on the Docker website. I found the information I needed at the below 2 links, but I'm copying the information here in case for some reason those links break or go away.

For Docker 1.4.1

Missing from the official install guide at the time of writing

First, install Docker normally according to the website: https://docs.docker.com/installation/mac/

Open up your ~/.bashrc or ~/.zshrc (depending on which shell you're using) and add the Docker environment variables by adding the following lines to the file:

export DOCKER_HOST=tcp://192.168.59.103:2376  # When you init Docker, it should give you an IP address.  This is the one I got, yours may be different.      
export DOCKER_CERT_PATH=/Users/<username>/.boot2docker/certs/boot2docker-vm                                                                                                     
export DOCKER_TLS_VERIFY=1  

configure the Proxy

http://stackoverflow.com/questions/24489265/docker-boot2docker-set-http-https-proxies-for-docker-on-osx

Quote from above SO answer: 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:

bash-3.2$ boot2docker ssh
Warning: Permanently added '[localhost]:2022' (RSA) to the list of known hosts.
*docker ascii art image*
boot2docker: 1.0.1
         master : cad5ece - Fri Jun 20 02:03:40 UTC 2014
docker@boot2docker:~$

Now create/modify /var/lib/boot2docker/profile to set proxy info:

docker@boot2docker:~$ sudo vi /var/lib/boot2docker/profile 

Tinycore needs the proxy info as follows: protocol://ip:port To be safe I set proxies for both HTTP and HTTPS.

# in the below, PPPP stands for your 4 digit port for the proxy
export HTTP_PROXY="http://username:password@your.proxy.name:PPPP"
export HTTPS_PROXY="http://username:password@your.proxy.name:PPPP"
export http_proxy="http://username:password@your.proxy.name:PPPP"
export https_proxy="http://username:password@your.proxy.name:PPPP"

Now you can restart the VM docker service and exit the VM.

docker@boot2docker:~$ sudo /etc/init.d/docker restart
docker@boot2docker:~$ exit
Connection to localhost closed.

You should be able to run the client against the VM instance now.

docker run hello-world

If that still doesn't work, run the following from the CLI:

    $ boot2docker stop && boot2docker up
    $ echo "$(boot2docker shellinit 2> /dev/null)" >> ~/.bashrc
    $ source ~/.bashrc
    $ docker run hello-world

If things still don't work, make sure the environment variables you set inside of your Boot2Docker VM are not set on the host. They can interfere with each other.

If things, yet, still don't work, try following the instructions below to upgrade docker or destroy and recreate the docker VM. Then, run through the above proxy configuration process again.

Note: If you will be using a corporate docker repository, but occasionally accessing the public docker repository, you may consider writing a shell script which can append/remove the proxy settings from the boot2docker profile configuration and restart the boot2docker instance.

Upgrading

You should be able to upgrade with 3 simple commands. Any changes that you made to your boot2docker VM (such as adding proxy settings to the /var/lib/boot2docker/profile) should be preserved through the upgrade.

    $ boot2docker stop
    $ boot2docker download # this step may take a while, and does not provide much progress feedback, so be patient
    $ boot2docker start

Exposing Docker Container Ports

This is different from the documentation on the Docker pages because Docker on OSX and Windows runs inside of a VirtualBox instance which runs Linux as the Guest OS.

You will find that if you run the suggested command:

    docker inspect <container id>

and then try to ping that IP address, you will not get a response back. This is because that IP is the docker container IP, which is exposed to Docker's host machine, which is not your locally running OSX or Windows OS, but rather the VirtualBox Linux Guest OS. So if you run the following from the Command Prompt/Bash Terminal:

    $ boot2docker ssh
    docker@boot2docker:~$ ping <IP from the docker inspect command>

You should now get a response from that IP address.

What does all of this mean? It means you need the port of your boot2docker VM exposed, not just that of the container. You do still need to expose the container's ports as well, though. Essentially, you are exposing the container's ports to it's host (the Boot2Docker VM), and then exposing the Boot2Docker VM's ports to it's host (your locally installed OS); A port forward of a port forward, if you will. The way to do all of this is as follows. Starting from the host machine, from either Command Prompt or from the Bash terminal...

    # -d runs the container as a daemon in the background
    # -p handles the containers port forwarding, where host_port is the port you want the service to run on on the host machine, and guest_port is the port the service is running on on the container
    $ docker run -d -p host_port:guest_port image:tag /command/to/run/service

    # Assuming Boot2Docker is running...
    $ VBoxManage controlvm "boot2docker-vm" natpf1 "rule-name,tcp,,host_port,,guest_port";
    $ VBoxManage controlvm "boot2docker-vm" natpf1 "rule-name,udp,,host_port,,guest_port";

An example of the above instructions applied to create a default ActiveMQ docker container

    $ docker run -d -p 61616:61616 activemq:latest /opt/activemq/bin/activemq start
    $ VBoxManage controlvm "boot2docker-vm" natpf1 "activemq,tcp,,61616,,61616";
    $ VBoxManage controlvm "boot2docker-vm" natpf1 "activemq,udp,,61616,,61616";

The above should now allow you to communicate to ActiveMQ through localhost:61616 on your native OS (either OSX or Windows).

You can test it out either by opening localhost:61616 in a web browser, or by running telnet localhost 61616 from the command line interface (Command Prompt or Bash).

I include both TCP and UDP in the above because the trip-up for me was I found exposing both worked, while exposing only TCP for some reason does not work for me. You may find that you need only either UDP or TCP, depending on your service and use-case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment