Joyent has recently announced their new Triton Docker container hosting service. There are several advantages of running Docker containers on Triton rather than on a more traditional cloud hosting platform:

  • Better performance since there is no hardware level virtualization overhead. Your containers run on bare metal.
  • Simplified networking between containers. Each container gets its own private (and optionally public) ip address.
  • Hosts are abstracted away – you just deploy into the “container cloud”, and don’t care which host your container is running on.

For more details, check out Bryan Cantrill’s talk about Docker and the Future of Containers in Production.

Let’s give it a spin with a “hello world” container, and then with a cluster of Couchbase servers.

Sign up for a Joyent account

Follow the signup instructions on the Joyent website.

You will also need to add your SSH key to your account.

Upgrade Docker client to 1.4.1 or later

Check your version of Docker with:

If you are on a version before 1.4.1 (like I was), you can upgrade Docker via the boot2docker installers.

Joyent + Docker setup

Get the sdc-docker repo (sdc == Smart Data Center):

Perform setup via:

Replace values as follows:

  • $ACCOUNT: you can get this by logging into the Joyent web ui and going to the Account menu from the pulldown in the top-right corner. Find the Username field, and use that
  • $PRIVATE_KEY_FILE: the name of the file where your private key is stored, typically this will be id_rsa

Run the command and you should see the following output:

Export environment variables

As the output above suggests, copy and paste the commands from the output. Here’s an example of what that will look like (but you should copy and paste from your command output, not the snippet below):

Docker Hello World

Let’s spin up an Ubuntu docker image that says hello world.

Remember, you’re running the Docker client on your workstation, not in the cloud. Here’s an overview on what’s going to be happening:

To start the docker container::

You should see the following output:

Also, since the --rm flag was passed, the container will have been removed after exiting. You can verify this by running docker ps -a. This is important because stopped containers incur charges on Joyent.

Congratulations! You’ve gotten a “hello world” Docker container running on Joyent.

Run Couchbase Server containers

Now it’s time to run Couchbase Server.

To kick off three Couchbase Server containers, run:

To confirm the containers are up, run:

and you should see:

At this point you will have environment variables defined with the container ids of each container. You can check this by running:

Get public ip addresses of the containers

Each container will have two IP addresses assigned:

  • A public IP, accessible from anywhere
  • A private IP, only accessible from containers/machines in your Joyent account

To get the public IP, we can use the Docker client. (to get the private IP, you need to use the Joyent SmartDataCenter tools, which is described below)

You will now have the public IP addresses of each container defined in environment variables. You can check that it worked via:

Connect to Couchbase Web UI

Open your browser to $container_1_ip:8091 and you should see the Couchbase welcome screen:

At this point, it’s possible to set up the cluster by going to each Couchbase node’s Web UI and following the Setup Wizard. However, in case you want to automate this in the future, let’s do this over the command line instead.

Setup first Couchbase node

Let’s arbitrarily pick container_1 as the first node in the cluster. This node is special in the sense that other nodes will join it.

The following command performs these operations:

  • Sets the Administrator’s username and password to Administrator / password (you should change this)
  • Sets the cluster RAM size to 600 MB

Note: the -u admin -p password should be left as-is, since that is just passing in the default admin name and password for auth purposes.

You should see a response like:

Create a default bucket

A bucket is equivalent to a database in typical RDMS systems.

You should see:

Add 2nd Couchbase node

Add in the second Couchbase node with this command

You should see:

To verify it was added, run:

which should return the list of Couchbase Server nodes that are now part of the cluster:

Add 3rd Couchbase node and rebalance

In this step we will:

  • Add the 3rd Couchbase node
  • Trigger a “rebalance”, which distributes the (empty) bucket’s data across the cluster

You should see:

If you see SUCCESS, then it worked. (I’m not sure why the “close failed in file ..” error is happening, but so far it appears that it can be safely ignored.)

Login to Web UI

Open your browser to $container_1_ip:8091 and you should see the Coucbase log in screen:

Login with:

  • Username: Administrator
  • Password: password

And you should see the Couchbase nodes:

Congratulations! You have a Couchbase Server cluster up and running on Joyent Triton.

Teardown

To stop and remove your Couchbase server containers, run:

To double check that you no longer have any containers running or in the stopped state, run docker ps -a and you should see an empty list.

Installing the SDC tools (optional)

Installing the Joyent Smart Data Center (SDC) tools will allow you to gain more visibility into your container cluster – for example being able to view the internal IP of each continer.

Here’s how to install the sdc-tools suite.

Install smartdc

First install NodeJS + NPM

Install smartdc:

Configure environment variables

Replace values as follows:

  • ACCOUNT: you can get this by logging into the Joyent web ui and going to the Account menu from the pulldown in the top-right corner. Find the Username field, and use that

List machines

Run sdc-listmachines to list all the containers running under your Joyent account. Your output should look something like this:

Find private IP of an individual machine

References

  • Native Docker API vs Joyent Triton API
  • https://www.joyent.com/blog/container-service-preview
  • https://www.joyent.com/blog/docker-bake-off-aws-vs-joyent
  • https://github.com/joyent/sdc-docker
  • https://github.com/joyent/sdc-docker/blob/master/docs/divergence.md

Posted by Traun Leyden, Senior Software Engineer, Couchbase

Traun Leyden is a Senior Software Engineer at Couchbase currently working on the Touch-DB/Android project. Prior to Couchbase, Traun co-founded Signature Labs, a venture-backed startup that developed an iOS mobile CRM geolocation app that was deployed in Fortune 500 companies. Among his accomplishments, Traun developed a highly popular Android ringer control app called "Buzzoff" and created an open source Neural Network library written in Go that leverages Go channels/goroutines to achieve high computation concurrency.

Leave a reply