Docker on Google Compute Engine Using Docker Machine

Docker on Google Compute Engine Using Docker Machine

Build Ship Run Banner

Docker on Google Compute Engine Using Docker Machine

Next up in Using Docker Machine across private and public clouds, is Google Compute Engine (GCE).

As with the other posts, a diagram of how I view the importance of a Docker Machine abstraction.

Docker Machine

First, if you don’t already have an account you can get $300 credit expiring after 60-days towards Google GCE that we will use as Docker hosts in this setup.

Setup your $300 in credit on GCE →

Configure Google Compute Engine to Enable Docker Containers and API Calls

Check this link for some of the pre-requisites to get your GCE account enabled for containers.

Once you have signed up, you will get dropped into a page with a project. Record the Project ID (api-project-xxxxxxxxxxxxx).

As a n00b to GCE it wasn’t clear in a couple of areas what the pre-reqs to get started were but I think there are at least two steps after signing up to start running Docker containers. Log into your Google Developers Console

  1. Head to the Developers Console and enable the “Google Container Engine API” from [APIs & Auth]-> [APIs] -> [Container Engine API] -> [Enable the API]
  2. Also inside the Google Developers Console, you need to enable billing for the Container Engine. [Compute]-> [Container Engine] -> [Enable Billing]

Create Docker Machines on GCE

See the Docker Machine docs for detailed descriptions and defaults of all of the Docker Machine flags.

The following is just the bare minimum for provisioning a machine:

If you haven’t seen GCE before you will get prompted for an OAUTH authentication which will spring a web page where you accept and auth with your gmail account.

I ran into a bit of an issue here only on setting up a new project. Once the project was good to go then the docker machine CRUD was perfect. It almost seemed like there was some delay in the project propagating after I enabled billing. After an error on billing not being enabled (listed below in troubleshooting) I got the following API response:

I poked around for about 30 minutes, created a new project, got the same errors and proceeded to install the gcloud client listed in Troubleshooting. Then things just started working,(of course ;_). I don’t think it was from doing anything with the gcloud client but its possible. I also listed my steps with that in case it was related. I haven’t had time to recreate the steps to validate the issue or if it was just someone giving the gremlins water after midnight.

This is all normal stuff and to be expected when getting setup, which is another reason I’m excited about moving towards some ubiquity in container API interfaces because there is no value to me as a consumer using different but same abstractions and implementations when the end goal is all the same. It seems trivial but it is part of the commodities recipe that containerization will drive compute towards and ultimately a race to zero. Moving on!

To delete the machine or if something wasn’t enabled properly on the Google side of your account you can delete the machine with the following (Note: force is used if there was an issue at provisioning and the instance is essentially orphaned meaning it exists on your docker machine side but not in GCE):

So here are two instances along with the rest of my free trial account stable of container ready docker host ponies in the cloud.

Seriously, that sexy.

Run Docker on GCE Machines

From here on it it’s smooth docker UI sailing.

Next verify the service you started. First by getting the IP address of the VM you started with docker-machine create.

Next curl the public port you started the service on using the IP address you just retreived:

The API supports stopping and starting, it does return /creating/deleting when /start/stop/ are called from the Google API but other then semantics the operations look good.

And a docker-machine stop:

Troubleshooting GCE Container Process

When you setup your GCE account, you have to enable billing as described above. If you don’t enable billing you will get an error like so:

This bit is optional but I was having issues with the project not being found so gave the client API a shot to see if it resolved anything. I dont think it did but it was helpful to validate information and API requests.

(Optional)Install gcloud client..

Then Auth.. Which will pop open a web browser to get a token.

Set the project name in your terminal to the project ID in the dev console

Thats it! Hopefully you are seeing the pattern of a common interface between dev/private/public virtual machines and provisioning containers within. Couple that with the ease of provisioning and de-provisioning services has both interesting Ops opportunities along with some serious potentials to reduce your cloud bills per workload by tearing down idle infra.

Thanks for stopping by!

About the Author

Brent SalisburyI have over 15 years of experience wearing various hats from, network engineer, architect, devops and software engineer. I currently have the pleasure of working at the company that develops my favorite software I have ever used, Docker. My comments here are my personal thoughts and opinions. More at Brent's BioView all posts by Brent Salisbury →