Joyent has recently announced their new Triton Docker container hosting service. There are several advantages of running Docker containers on Triton over 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.
Install or Upgrade Docker
If you don’t have Docker installed already and you are on Ubuntu, run:
1
|
|
See install Docker on Ubuntu for more details.
Upgrade Docker client to 1.4.1 or later
Check your version of Docker with:
1 2 |
|
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):
1
|
|
Perform setup via:
1 2 |
|
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
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):
1 2 3 |
|
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::
1
|
|
You should see the following output:
1 2 3 4 |
|
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:
1 2 3 4 |
|
To confirm the containers are up, run:
1
|
|
and you should see:
1 2 3 4 |
|
At this point you will have environment variables defined with the container ids of each container. You can check this by running:
1 2 3 4 |
|
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)
1 2 3 |
|
You will now have the public IP addresses of each container defined in environment variables. You can check that it worked via:
1 2 3 4 |
|
Connect to Couchbase Web UI
Open your browser to $container_1_ip:8091 and you should see:
At this point, it’s possible to setup 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 will do the following:
- Set the Administrator’s username and password to Administrator / password (you should change this)
- Set 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.
1 2 3 4 5 6 |
|
You should see a response like:
1
|
|
Create a default bucket
A bucket is equivalent to a database in typical RDMS systems.
1 2 3 4 5 6 7 8 |
|
You should see:
1
|
|
Add 2nd Couchbase node
Add in the second Couchbase node with this command
1 2 3 4 5 6 |
|
You should see:
1
|
|
To verify it was added, run:
1 2 3 |
|
which should return the list of Couchbase Server nodes that are now part of the cluster:
1 2 |
|
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
1 2 3 4 5 6 |
|
You should see:
1 2 3 4 5 6 |
|
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:
Login with:
- Username: Administrator
- Password: password
And you should see:
Congratulations! You have a Couchbase Server cluster up and running on Joyent Triton.
Teardown
To stop and remove your Couchbase server containers, run:
1 2 |
|
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:
1
|
|
Configure environment variables
1 2 3 |
|
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
Find private IP of an individual machine
1
|
|