How to run Docker on CloudSigma (with CloudInit)

Pre-requisites:

In the recent year or so, Docker has received a tremendous amount of attention. It appears to be one of those things where the timing was just perfect. While the concept of containers is hardly anything new (which I talked more about in this previous post), Docker appears to have become the go-to container manager.

Assuming you’re already familiar with the basics of Docker, you might be interested in the easiest way to deploy Docker on CloudSigma.

As it turns out, this is very simple to automate. What we’ll be using is CloudInit and Ubuntu’s Cloud Images (named “Ubuntu 14.04 Cloud Image” in the Marketplace).

Once you’ve cloned this and created a server with this image, go ahead and resize it. The template image is just slightly larger than 2GB, which isn’t sufficient for this. 5-15GB is more suitable.

With that done, click on the new ‘CloudInit’ link under the Properties of your server.

Docker with cloudinit

Now paste in the following and press ‘Activate’ (and then save your server):

[bash] #cloud-config
package_upgrade: true
package_reboot_if_required: true
ssh_authorized_keys:
– Your-Public-SSH-Key
packages:
– docker.io
runcmd:
– ln -sf /usr/bin/docker.io /usr/local/bin/docker
– sed -i ‘$acomplete -F _docker docker’ /etc/bash_completion.d/docker.io
final_message: "Your Docker server is now ready."
[/bash]

If you’re not familiar with CloudInit, let’s run through what this does.

  • Line 2: Upgrade all packages and brings the system up to date.
  • Line 3: If the updates on line one requires a reboot, go ahead and do it.
  • Line 4-5: Tell the system to install the public SSH key (Your-Public-SSH-Key) to the user ‘ubuntu’
  • Line 6-7: Install the package ‘docker.io’. This also implies ‘package_update: true’.
  • Line 8-10: Usability enhancement from the official installation guide.
  • Line 11: Display a message when done.

Shortly after you’ve booted up the server, you should be able to SSH into the server using your SSH key. Depending on the number (and types) of updates that were installed, your server may or may not reboot (Line 3 above). As a result, you may not see the final message.

After CloudInit is done, you should now be up and running with Docker:

[bash light=”true”] $ ssh ubuntu@a.b.c.d "sudo docker ps"
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[/bash]

Voilá. You now have a server up and running with Docker. This can of course be automated using our API too, in case you need to create multiple servers.

Share this Post

About Viktor Petersson

Former VP of Business Development at CloudSigma. Currently CEO at WireLoad and busy making a dent in the Digital Signage industry with Screenly. Viktor is a proud geek and loves playing with the latest technologies.

Leave a Reply