So I decided to participate in #DockerGlobalHackday and oh boy was it a learning experience. First off, the hackday started off with great presentations from some of the hackers and docker contributors. One that caught my eye was Host Management (https://www.youtube.com/watch?v=lZGmvGw-mWc) and (https://github.com/docker/docker/issues/8681)
Ben Firshman and contributors thought up and created this feature for Docker that lets you provision remote daemons on demand given cloud providers. It had me thinking that maybe I should hack on a driver for a Local Openstack Deployment. So I did, and this is my DockerHackDayHack.
https://github.com/wallnerryan/docker/tree/host-managment-openstack
*Note, the code is raw, very raw, I haven’t coded in Go until this Hackday 🙂 Which is what I guess it is good for.
*Note this code was developed using Devstack with Flat Network orignaly, so there is some rough edged code for supporting out of the box devstack with nova network but it probably won’t work 🙂 I’ll make an update on this soon.
*Note the working example was testing on Openstack Icehouse with Neutron Networking. Neutron has one public and one private network. The public network is where the floating ip comes from for the docker daemon.
Here are the options now for host-management:
./bundles/1.3.0-dev/binary/docker-1.3.0-dev hosts create
Notice the areas with “–openstack-” prefix, this is what was added. If your using neutron network then the network for floating ips is needed. The image can be a Ubuntu or Debian based cloud image, but must support Cloud-Init / Metadata Service. This is how the docker installation is injected.Below is an example of how to kickoff a new Docker OpenStack Daemon: (beware the command is quite long with openstack options, replace X.X.X.X with your keystone endpoint, as well as UUIDs of any openstack resources.) It also includes –openstack-nameserver, this is not required but in my case I was, and will inject a nameserver line into the resolve.conf of the image using Cloud-Init / Metadata Service
In the future I plan on making this so we don’t need as many UUIDs. but rather the driver will take text as input and search for the relevant UUIDs to use. ( limited time to hack on this )
#./bundles/1.3.0-dev/binary/docker-1.3.0-dev hosts create -d openstack
–openstack-image-id=”d4f62660-3f03-45b7-9f63-165814fea55e” \
–openstack-auth-endpoint=”http://X.X.X.X:5000/v2.0” \
–openstack-floating-net=”4a3beafb-2ecf-42ca-8de3-232e0d137931″ \
–openstack-username=”admin” \
–openstack-password=”danger” \
–openstack-tenant-id=”daad3fe7f60e42ea9a4e881c7343daef” \
–openstack-keypair=”keypair1″ \
–openstack-region-name=”regionOne” \
–openstack-net-id=”1664ddb9-8a14-48cd-9bee-a3d4f2fe16a0″ \
–openstack-flavor=”2″ \
–-openstack-nameserver=”10.254.66.23″ \
–openstack-secgroup-id=“e3eb2dc6-4e67-4421-bce2-7d97e3fda356” \
openstack-dockerhost-1
The result you will see is: (with maybe some errors if your security groups are already setup)
#[2014-11-03T08:31:51.524125904-08:00] [info] Creating server.#[2014-11-03T08:32:16.698970304-08:00] [info] Server created successfully.#%!(EXTRA string=63323227-1c1e-40f6-9c25-78196010936b)[2014-11-03T08:32:17.888292214-08:00] [info] Created Floating Ip#[2014-11-03T08:32:18.439105902-08:00] [info] “openstack-dockerhost-1” has been created and is now the active host. Docker commands #will now run against that host
(View Hosts)./bundles/1.3.0-dev/binary/docker-1.3.0-dev hostsYou can make either the local unix socket or the openstack node the active Daemon and you can use it like any other docker client. This “hosts” command can run locally on your laptop but your containers and daemon run in OpenStack. One could see this feature replacing something like Boot2Docker.(docker ps) – Shows containers running in your openstack deployed docker daemon./bundles/1.3.0-dev/binary/docker-1.3.0-dev ps -a
{ "variables": { "ssh_name": "yourname", "ssh_pass": "password", "hostname": "packer-ubuntu-1204" }, "builders": [{ "type": "virtualbox-iso", "guest_os_type": "Ubuntu_64", "vboxmanage": [ ["modifyvm", "{{.Name}}", "--vram", "32"], ["modifyvm", "{{.Name}}", "--memory", "2048"], ["modifyvm", "{{.Name}}","--natpf1", "web,tcp,,8080,,80"], ["modifyvm", "{{.Name}}","--natpf1", "fivethousand,tcp,,5000,,5000"], ["modifyvm", "{{.Name}}","--natpf1", "ninesixninesix,tcp,,9696,,9696"], ["modifyvm", "{{.Name}}","--natpf1", "eightsevensevenfour,tcp,,8774,,8774"], ["modifyvm", "{{.Name}}","--natpf1", "threefivethreefiveseven,tcp,,35357,,35357"] ], "disk_size" : 10000, "iso_url": "http://releases.ubuntu.com/precise/ubuntu-12.04.4-server-amd64.iso", "iso_checksum": "e83adb9af4ec0a039e6a5c6e145a34de", "iso_checksum_type": "md5", "http_directory" : "ubuntu_64", "http_port_min" : 9001, "http_port_max" : 9001, "ssh_username": "{{user `ssh_name`}}", "ssh_password": "{{user `ssh_pass`}}", "ssh_wait_timeout": "20m", "shutdown_command": "echo {{user `ssh_pass`}} | sudo -S shutdown -P now", "boot_command" : [ "<esc><esc><enter><wait>", "/install/vmlinuz noapic ", "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ", "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ", "hostname={{user `hostname`}} ", "fb=false debconf/frontend=noninteractive ", "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ", "keyboard-configuration/variant=USA console-setup/ask_detect=false ", "initrd=/install/initrd.gz -- <enter>" ] }] } (Preseed.cfg Starts HERE) # Some inspiration: # * https://github.com/chrisroberts/vagrant-boxes/blob/master/definitions/precise-64/preseed.cfg # * https://github.com/cal/vagrant-ubuntu-precise-64/blob/master/preseed.cfg # English plx d-i debian-installer/language string en d-i debian-installer/locale string en_US.UTF-8 d-i localechooser/preferred-locale string en_US.UTF-8 d-i localechooser/supported-locales en_US.UTF-8 # Including keyboards d-i console-setup/ask_detect boolean false d-i keyboard-configuration/layout select USA d-i keyboard-configuration/variant select USA d-i keyboard-configuration/modelcode string pc105 # Just roll with it d-i netcfg/get_hostname string this-host d-i netcfg/get_domain string this-host d-i time/zone string UTC d-i clock-setup/utc-auto boolean true d-i clock-setup/utc boolean true # Choices: Dialog, Readline, Gnome, Kde, Editor, Noninteractive d-i debconf debconf/frontend select Noninteractive d-i pkgsel/install-language-support boolean false tasksel tasksel/first multiselect standard, ubuntu-server # Stuck between a rock and a HDD place d-i partman-auto/method string lvm d-i partman-lvm/confirm boolean true d-i partman-lvm/device_remove_lvm boolean true d-i partman-auto/choose_recipe select atomic d-i partman/confirm_write_new_label boolean true d-i partman/confirm_nooverwrite boolean true d-i partman/choose_partition select finish d-i partman/confirm boolean true # Write the changes to disks and configure LVM? d-i partman-lvm/confirm boolean true d-i partman-lvm/confirm_nooverwrite boolean true d-i partman-auto-lvm/guided_size string max # No proxy, plx d-i mirror/http/proxy string # Default user, change d-i passwd/user-fullname string yourname d-i passwd/username string yourname d-i passwd/user-password password password d-i passwd/user-password-again password password d-i user-setup/encrypt-home boolean false d-i user-setup/allow-password-weak boolean true # No language support packages. d-i pkgsel/install-language-support boolean false # Individual additional packages to install d-i pkgsel/include string build-essential ssh #For the update d-i pkgsel/update-policy select none # Whether to upgrade packages after debootstrap. # Allowed values: none, safe-upgrade, full-upgrade d-i pkgsel/upgrade select safe-upgrade # Go grub, go! d-i grub-installer/only_debian boolean true d-i finish-install/reboot_in_progress note