Follow Me Icons

 

Follow @KendrickColeman on TwitterConnect on LinkedInWatch My Videos on YouTubeFollow me on FacebookCheck Out My Projects on GitHubStay Up To Date with RSS

Search

BSA 728x90 Center Banner

Docker Machine and Complete Customization

NOTE: THIS IS NOT SUPPORTED BY DOCKER OR EMC. THIS IS NOT EVEN A CONSIDERED A VERSION OF DOCKER MACHINE. THIS IS A PROJECT FLING TO PROVE THE ABILITY.

TL;DR get the Docker Machine with Extensions binary and try it yourself. Or watch the youtube video at the very bottom to see it in action.

 

I've had some fun playing with Go the past few weeks and I was able to create a very powerful customization. I present to you Docker Machine with Extensions! Using a standard template, it's possible to have a completely customized Docker Machine installation.

 

But, why is this important? 

 

Docker Machine gets you a “docker ready” host. It automatically configures the host OS to run Docker containers and can be joined to a Swarm cluster. But what about everything else that goes into daily operations? Configuration management, Docker Engine pluggable extensions, crazy security configurations, etc! Those are the things that can push Docker Machine that extra mile.

 

The EMC {code} team came up with a clever way to have generic and native “extensions” using a standard JSON file. In short, here is what a JSON file allows you to do:

  • Environment Variables: Set environment variables to /etc/environment that could be used for customization of anything
  • Copy: Specify a source and destination and it will invoke the docker-machine scp command to move files from your local host to a remote host or between remote hosts. This can be used to move binaries, transfer configuration files, etc.
  • Run: Create an ordered list of commands to run. Install packages, move files, or do anything.
  • ValidOS: Specify a range of operating systems that will work with this configuration.

 

 

Then we can get even more specific with these JSON parameters that can be used for a native extension:

  • Version: Keep version control and make sure that you are installing a specific version or perhaps the latest stable release. This becomes critical when going to production and you have to pair your service with a certain version of the Docker Engine.
  • Params: Any key:value pair that you can specify for the service/extension’s use.
  • Files: sort of like Copy from earlier but is an ordered list of files so they are transferred in chronological order using docker-machine scp.

 

The possibilities are endless:

  • Apply your company’s security template to a standard OS like Ubuntu or Red Hat without having to use a specific golden image or AMI.
  • Change specific OS settings that point to internal DNS or NTP servers
  • Install packages like Nagios for server or service monitoring
  • Install software binaries and run installation scripts
  • Install agents that hook back into other systems like Chef, Puppet and even Mesos!

 

Lets get a generic JSON file that will do a few things:

{
   "extensions": [
   {
     "generic": {
       "copy": {
         "/Users/kcoleman/Desktop/networkconfig.txt": "/etc/network/interfaces"
       },
       "run": [
         "sudo ifdown --exclude=lo -a && sudo ifup --exclude=lo -a"
       ],
       "validOS": [
         "ubuntu",
         "debian"
       ]
     }
   }
 ]
}

 

From this JSON file we can see that we are going to transfer over a new network configuration and then restart the network interfaces. This will only run if the host OS is Ubuntu or Debian.

 

What about something more in depth? Lets install multiple extensions!

{
  "extensions": [
    {
      "generic": {
        "copy": {
           "/Users/kcoleman/Desktop/rexconfig.yaml": "/etc/rexray/config_backup1.yaml"
        }
      }
    },
    {
      "weave": {
        "params": {
          "peer": "192.168.10.101"
        }
      }
    },
    {
      "rexray": {
        "version": "latest",
        "files": {
           "config.yaml": {
               "source": "/Users/kcoleman/Desktop/rexconfig.yaml",
               "destination": "/etc/rexray/config.yaml"
            }
        }
    }
  },
  {
    "generic": {
       "copy": {
           "/Users/kcoleman/Desktop/rexconfig2.yaml": "/etc/rexray/config_backup3.yaml"
        }
    }
   }
  ]
}

 

At this stage, REX-Ray and Weave are two native extensions that have been tested and work. But we are first using the generic extension to transfer the file as a backup of the REX-Ray configuration. Next we are installing Weave and pairing it to the peer node. Next we are installing the REX-Ray extension using the latest version and specifying that we want to replace the config.yaml file with our own. Lastly, we are transferring over another file for lols.

 

Create your own JSON file and see what you can come up with! Check out more extension examples at kacole2/machine-extensions.

 

Download the binary from kacole2’s branch and run Docker Machine with the --extension yourfile.json command:

./docker-machine_darwin-amd64 -D create --driver amazonec2 --amazonec2-access-key <key> --amazonec2-secret-key <secret key> --amazonec2-vpc-id <vpc-id> --extension /Users/kcoleman/Desktop/happyfun.json devext

 

This is just an experiment and not officially in Docker Machine yet, but that the declarative configuration (Issue #773.) is an active topic and any feedback is welcome to the code and machine team

 

 

this was first published on my team's blog at blog.emccode.com

Related Items