Learning Docker on Google Cloud Platform : CoreOS is your Friend

In an earlier blog post, I had presented the view that one of the best ways to learn Docker in my opinion is to move to the cloud and not do this stuff on your local machine. Chief reasons among them being bandwidth issues that could completely spoil your experience around Docker.

I usually recommend Google Cloud Platform to almost anyone that I meet due to its simplicity and behind the scenes power that is provided to you via Google’s amazing infrastructure. However, this is not the post for that.

So, assuming that you want to get started with Google Cloud Platform as a vehicle to learn Docker, I suggest that you do the following:

Sign up for Google Cloud Platform

There is a free trial period of 2 months with a credit for $300 and this should be sufficient for your needs to learn Docker. I am not a marketing vehicle for anyone but you will love the platform and the power that it gives you.

Create Compute Engine instance

Compute Engine is the Infrastructure as a Service (IaaS) component in Google Cloud Platform. While it is a vast topic, our goal here is to simply get ourselves a Virtual Machine (Compute Engine instance).

To do that, go to the Compute Engine –> VM Instances option in Developer Console for your project. Click on Create Instance.

This should lead you to a form where you can define your resource (VM) capabilities in terms of Processor, RAM , which Operating System, which Region it should be hosted in and so on.

Just focus on the following attributes while filling up the form for Create a new instance:

  • Name : Give a name to your instance. For e.g. yourname-01
  • Firewall : Enable HTTP traffic. You might need it if you plan on setting up some web servers using Docker which rely on the default port 80. If you wish to keep this unchecked, remember to come back to Firewall settings to eventually open up your server to the world.
  • Zone : Leave it as is, unless you are particular about where your instance should reside. Remember that each region has its own pricing. When you grow to more serious projects around Google Cloud Platform, this is an important thing to keep in mind.
  • Machine type : I suggest you leave it with the default one. But do look around in the list if you want extra computing power. Remember cost is a factor. If you want to downgrade the processing power a bit, that is fine too.
  • Image : This is very important. While you can go with several Linux based distributions and then install Docker on them – I suggest do not go there. Go for the image type CoreOS (coreos-stable-*). This is a Linux OS that is containerized from the grounds up and has Docker installed for you, so that you are good to go the moment you fire up the instance and SSH into it. This OS opened my eyes to some solid architecture and you should definitely take a look at it. Especially for a predominantly Windows person that I have been for a majority of my career, you will love what you see. It should give you enough A Ha! moments as you go along. And by the way, the music group A Ha! is a favourite of mine.

    Let me give you a hint: Applications on CoreOS run as Docker containers. 

  • Leave all the other options at their defaults. And click on Create.

This should create the Compute Engine instance for you. For e.g. if you named your instance as yourname-01, you should see the instance listed when you go to the Compute Engine –> VM Instances page.

You will see a button titled “SSH” next to each Compute Engine instance that you create. This will directly enable you to SSH into the running VM instance via the browser itself. This is a very useful feature to avoid any other tools to be setup on your machine.

Once you successfully SSH into the instance, you should see the familiar Linux Screen. A sample screenshot is given below:

Screen Shot 2015-03-27 at 6.14.54 pm

Begin your Docker journey NOW!

Try out a few commands as given below:

Screen Shot 2015-03-27 at 6.17.45 pm

Obviously we do not have any images right now and if we run docker images, there will be none listed but that is just the start.

If you are itching to get started, check out the Getting Started Guides at:

Additional Notes on Google Cloud Platform

Google Cloud Platform provides 3 ways to interact with it, as a client. They are:

  1. Web Console (which I described above) and which you access via the web browser.
  2. REST API
  3. Google Cloud SDK , which provides a set of command line utilities that you can install on your machine (It supports Windows, Mac and Linux) and execute commands from your terminal/command prompt.

So everything that I mentioned via the Web console can be done by (2) and (3) – but since the focus was on learning Docker and using Cloud resources, I did not want to create any local setup for you.

Google Cloud Platform also provides Container optimized Linux Images for your to use while creating the instance. If you are familiar with the Google Cloud SDK from the command line / terminal and want to use the gcloud tool to create instances, do read up on Container VMs.

 

Learning Docker ? Move To The Cloud !

DockerLogo

Docker is all the rage and there are valid reasons for it. Every software developer needs to understand this fundamental shift that is happening when it comes to packaging, delivering and running applications as containers. It would definitely pay to start learning this technology. There are enough resources on the Net to do that today and hopefully I will come around with some tutorials that can help demonstrate how useful Docker can be to individual developers like you and me.

The focus of this blog post is different though. It is about which platform/OS should I start learning Docker on. And then I would like to make some points from the perspective of countries/individuals where it is not easy to get high speed internet access all the time for several reasons. My focus is going to be for students who want to get started and have limited resources.

Which platform : Linux, Mac or Windows?

So first up is which platform ? It is clear from the current state of Docker that it runs natively only on Linux and not on Mac or Windows. Agreed that there are solutions like boot2docker available that make it possible to run on Mac or Windows. But let me throw out Mac from the equation altogether. Nothing against the OS as such but in my experience from where I stay, the developers that I talk to and current circumstances, I believe 1 in 1000 people have a Mac as compared to a Linux or Windows laptop. The simple reason is that of economics.

boot2docker is good! But keep it on hold for a moment!

Despite that I suggest that you do not do anything locally even via boot2docker. The chief reason (and I won’t go into every detail) is that when building up initial docker images, you have to start with some version of the OS. That is perfectly fine but the problem that comes up is that this initial download of the base OS image that you begin to work with is likely to run into 100’s of MB that need to be downloaded first. This is both time consuming (on slow Internet access) and possibly expensive too for you to upgrade to more expensive plans. As a student of the subject, you want to see results quickly. The First Time To Hello World (FTTHW) has to be as minimal as possible to create the right impact for you. Given that, take my advice that in the initial days of your learning – keep away from this loop.

Embrace the Cloud

So what does that leave you with? It leaves you with the IaaS providers like AWS, Google Cloud Platform (GCP), Azure and others. Yes, it is going to cost you a bit but believe me it is a very minimal expense to rent out a Linux Box on the high quality, top class networks that your instance is hosted with and blazing fast network access to Docker images.

This is what I have been doing for the past several weeks and have been recommending to all folks that I come across:

  1. Go ahead and get yourself an account on Google Cloud Platform. It is easy to get started and you even get a $300 credit for a trial period of 2 months. Trust me $300 is a lot of money for IaaS services , especially if you are looking to learn about the platform and its services.
  2. Provision a Google Compute Engine (GCE) instance. Select one of the Linux images available and you are all set to install docker.io and move forward with it.
  3. As an alternative to Step 2, you can directly create a GCE instance of a Container VM image itself so that it is all setup with Docker. Check out the documentation on how to do that.

Parting thoughts

I believe the above steps will keep the productivity high and keep your costs to a minimum. Once you are done with the instance, you can simply delete it. Once you have your head wrapped around Docker, you will be better prepared to then go ahead and do stuff that you want on your local machine.

Some folks mention that the online Docker tutorial is good enough. I agree to some extent but there is nothing compared to setting up your own box and playing with Docker on your own. This way you can experiment with other Docker images, build a few yourself and go through the mechanics of Docker present at the official documentation site. Do try out the examples, especially the ones that are relevant to the software stack that you are working on.

I would love to hear your thoughts on this. It is possible that I might have completely missed out something.

Note: I have taken the example of Google Cloud Platform that I primarily use. Linux Instances are available on any other cloud provider too, so pick your choice.

 

Google Cloud Platform Updates – Articles

Over the last couple of weeks I have covered the news around several features that have been released on Google Cloud Platform (GCP). I write these articles on ProgrammableWeb. Here are the list of articles:

The articles demonstrate the recent spate of feature releases on GCP. They are targeted squarely towards the developers/organizations and helping them get more productive, write secure apps and finally get a shot at a messaging service in GCP. Not to speak of Google Cloud Storage Nearline that changes the game when it comes to cold data storage.

 

Android Studio + Cloud Endpoints + Objectify Persistence

Android Studio has solid support for working with Google Cloud Endpoints. I have written a series of tutorials on working with Gradle, Android Studio, Cloud Modules over here. One of the episodes in that chapter was around generating the Persistence Layer in your Endpoints using Objectify.

At the time of that writing, the skeleton wrapper code that was generated for Endpoint when you provide it your Entity class was minimal. It was of not much use and you had to pretty much write the Objectify code for list, get, add, update and remove methods.

Since then the support has been upped by several notches and I should have written about this earlier but got around to it only now. The bottom line is that if you have an Objectify annotated Entity code, Android Studio is currently doing a great job of generating the Endpoints class with all the persistence goodness of Objectify generated for you. This can greatly help to reduce the time to generate working persistence code for your Mobile backend.

Continue reading