When I’m at events and conferences I’m always asked how much does Couchbase charge for hosting. The simple answer is that Couchbase is
a software company and not a hosting company, but that doesn’t mean that you can’t host Couchbase through some other service. There are Couchbase
images available on services including Amazon Web Services (AWS), Azure, Joyent, and many others.
In particular, we’re going to look at hosting Couchbase Server on Joyent’s Triton platform with Docker.
A Background on Joyent and Triton
If you’re unfamiliar with Joyent, it is a software and services company that specializes in performance driven public and private cloud
computing. Using Joyent’s Triton service, you can “…securely deploy and operate containers with bare metal speed on
container-native infrastructure”. Some of the advantages of running Docker containers on Triton include:
- Your containers run on bare metal, eliminating hardware level virtualization overhead. In other words you will experience
significantly improved performace. - Each container has its own IP address which makes it easier to network between containers.
- You can resize your Docker containers with no down time.
The Requirements
Being that we’re going to get a Couchbase Server cluster up and running on Joyent’s Triton, there will be a few requirements in the process:
- Docker 1.8
- A Joyent Account
- An SSH Private Key
You can probably get away with using a different version of Docker, but I’m using 1.8. It is up to you how adventurous you want to be.
Using Couchbase with Docker Containers
At this point, if you haven’t already installed the Docker Toolbox, now is a
good time. It will contain all the tools necessary for using Docker on our local computer.
Now the Docker Toolbox contains a tool called Kitematic, offering GUI support for Docker. We won’t be using that tool. Instead we are going
to do everything from the Terminal (Mac and Linux) or Command Prompt (Windows).
Note that for now we are going to use Docker locally only, just to become familiar with Couchbase and Docker. Later in this guide we’ll be
connecting to Joyent’s Triton service.
Download and Start a Couchbase Server Container
From the Docker Terminal application, run the following command:
1 2 3 |
docker run --name couchbase-server-1 -d -p 8091:8091 couchbase |
The above command will download the latest official Couchbase Server Docker image, give the container a name on our system, and start it.
You can test that it was successful by visiting http://192.168.99.100:8091/ in your browser. Note
that 192.168.99.100 is whatever your Docker Terminal told you when you started it.
Start a Second Couchbase Server Container
Go ahead and start up a second local Couchbase Server instance with Docker. This time you want to do the following:
1 2 3 |
docker run --name couchbase-server-2 -d -p 8092:8091 couchbase |
Notice this time we changed the container name and increased the host port to 8092 instead of 8091. This
is to prevent port conflicts.
Stop and Remove Both Couchbase Server Containers
We no longer need these locally running Couchbase Server Docker containers. To remove them, we must first figure out their unique
container value like so:
1 2 3 |
docker ps |
The result will look something like this:
1 2 3 4 5 |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9f3b05af8393 couchbase "/entrypoint.sh couch" 9 minutes ago Up 9 minutes 8092-8093/tcp, 11207/tcp, 11210-11211/tcp, 18091-18092/tcp, 0.0.0.0:8092->8091/tcp couchbase-server-2 b20045600bd0 couchbase "/entrypoint.sh couch" 9 minutes ago Up 9 minutes 8092-8093/tcp, 11207/tcp, 11210-11211/tcp, 0.0.0.0:8091->8091/tcp, 18091-18092/tcp couchbase-server-1 |
With the unique container values you can then run:
1 2 3 4 5 6 |
docker stop 9f3b05af8393 docker stop b20045600bd0 docker rm 9f3b05af8393 docker rm b20045600bd0 |
Both local containers should now be removed.
Connecting Docker to the Triton Cloud API
Up until now, everything Docker and Couchbase was local to your machine. Now we’re going to connect our Docker client to the Joyent
Cloud API so we can make use of Triton. The steps we’re going to follow can be found in
the official Joyent documentation, but can also be seen in this guide.
Start by obtaining the Joyent helper script like so:
1 2 3 |
curl -O https://raw.githubusercontent.com/joyent/sdc-docker/master/tools/sdc-docker-setup.sh |
If you don’t have or can’t use curl download the file manually. With the script downloaded, you want to now execute it,
passing in a particular set of parameters:
1 2 3 |
bash sdc-docker-setup.sh ~/.ssh/ |
The CLOUDAPI_URL can be one of the following, per the documentation:
- https://us-east-1.api.joyent.com
- https://us-sw-1.api.joyent.com
- https://eu-ams-1.api.joyent.com
The ACCOUNT_NAME is the username you use to sign into the Joyent dashboard. Like mentioned earlier, you’ll need an SSH
private key to plug into PRIVATE_KEY_FILE.
When you run the script, it may ask you to enter your private key password a few times. Just follow the instructions and do as it says. At
the end, it will supply you with something that looks like the following:
1 2 3 4 5 6 |
export DOCKER_CERT_PATH=/Users/nraboy/.sdc/docker/nraboy export DOCKER_HOST=tcp://us-east-1.docker.joyent.com:2376 export DOCKER_CLIENT_TIMEOUT=300 export DOCKER_TLS_VERIFY=1 |
You’ll want to run those export statements, but don’t forget to change my nraboy to that of whatever
it generated for you. These export statements are important because once you run them, Docker will then use Joyent for managing
containers instead of your local machine.
Run Couchbase Server Containers on Joyent
Remember those local Docker commands we ran earlier? Let’s run them again with a minor modification:
1 2 3 |
docker run --name couchbase-server-1 -d -P couchbase |
We shouldn’t need to define port mapping on our own when it comes to Joyent. This is because Joyent gives us an IP for every container we
create. On our local machine we only have one IP and ports become an issue. Just make use of the -P flag and you
should be good.
If you sign into your Joyent dashboard you should see the node and its IP address. If you don’t want to obtain the information via
the Joyent dashboard, you can always do this via the Docker Terminal because everything it does is on the remote side now:
1 2 3 4 |
docker ps docker inspect --format '{{ .NetworkSettings.IPAddress }}' 9f3b05af8393 |
Remember of course to switch out the unique container id with those returned from docker ps.
Configure Your First Couchbase Node
Using one of the IP addresses returned from the docker inspect command, enter it in your web browser with port
8091 appended. Something like http://165.225.158.112:8091 will do it.
Walk through the steps for configuring the Couchbase cluster. Remember the IP and administrator credentials as they’ll be needed when
adding new nodes to your cluster.
Add More Nodes to Your Couchbase Triton Cluster
Time to add another Couchbase Server container to Triton so we can cluster our Couchbase nodes. From the Docker Terminal run:
1 2 3 |
docker run --name couchbase-server-2 -d -P couchbase |
Like we discussed earlier, get the IP of this container and boot it up in your web browser on port 8091.
Instead of choosing to create a new Couchbase cluster, choose to join one and enter the information of the other server. When complete,
rebalance the server and you’re good to go!
Remove Containers from Your Cluster
Being that Couchbase is pretty scalable, you’ll probably find yourself needing to remove nodes every once in a while. To do this, you’ll
need to first gracefully remove the Couchbase node from your cluster via the Couchbase administrative dashboard. The removal will include
a rebalance of all of your existing nodes.
With the node safely removed from the cluster, you can now remove its container from Joyent’s Triton service. In your Docker Terminal proceed
with the same steps we followed when we removed a container locally:
1 2 3 4 5 6 7 |
docker ps docker stop 9f3b05af8393 docker stop b20045600bd0 docker rm 9f3b05af8393 docker rm b20045600bd0 |
Remember of course to swap out the unique container ids with those returned from docker ps.
Conclusion
We just saw how to make use of Joyent’s Triton service to host Docker containers with Couchbase Server. Using Joyent will give you incredible
performance with its bare-metal infrustructure and excellent security.
The topic of security was out of the scope for this particular article, but it may be revisited in a future post.
To compliment this article, Joyent is giving Couchbase users a promotional discount on its Triton service. You can sign up for Joyent and
make use of this offer here.