Thursday, May 7, 2015

How to setup docker as a development tool OSX

  • Install Virtualbox
  • Assuming you have Brew installed, install boot2docker
  • If you use a proxy to connect to the internet, Implement transparent proxying (this'll be a bit of work, and worthy of a blog post of its own)
  • Setup your internal networking to allow direct access to containers
    • In the Global settings of Virtual box, add a second 'host-only-network', and give it these settings:
      • ipv4 address : 172.16.0.1
      • ipv4 network mask : 255.255.255.0
      • ipv6 address : blank
      • ipv6 network mask length  : 0
      • Uncheck DHCP server
    • In the settings of the boot2docker vm, add the host only adapter we created in the last step as 'Adapter 3'
    • Start the boot2docker vm, adding the environment variables as instructed
    • Remote onto the boot2docker vm and run the following
      • sudo ifconfig eth2 172.16.0.11
      • sudo ifconfig eth1 netmask 255.255.0.0
    • On your mac, run the following
      • sudo route -n add 172.17.0.0/16 $(boot2docker ip)
    • Bring up a test container :
      • docker run -t -i ubuntu /bin/bash
    • The containers should now be network accessible, to test this, in another terminal run
      • docker inspect
      • There'll be an IP address in the output, it should be ping-able
  • We'll use skydock / skydns to provide accessible host names for the containers
    • docker run -d -p 53:53/udp --name skydns crosbymichael/skydns -domain docker
    • docker run -d -v /var/run/docker.sock:/docker.sock --name skydock crosbymichael/skydock -ttl 30 -environment dev -s /docker.sock -domain docker -name skydns
  • To route all dns requests for the docker domain to a skydock/skydns server, run the following
    • sudo echo "nameserver 192.168.59.103" > /etc/resolver/docker
  • Docker containers should now be available at addresses in the form of, . .dev.docker i.e. rabbitmq01.rabbitmq.dev.docker
  • If multiple containers are running with the same image, they can be loadbalanced with .dev.docker i.e.  rabbitmq.dev.docker

No comments: