Our mission at ObjectRocket is to provide the fastest, most reliable databases available. There are plenty of great places to run your applications, but the role that containers (and Docker in particular) play in the enterprise today is undeniable. Rackspace recently released a great new service called ‘Carina’, providing a high performance hosted Docker Swarm service that complements ObjectRocket very well. In this post, I’d like to show you how to get started deploying and scaling applications on Carina, while easily integrating with blazing fast databases on ObjectRocket.
First, head on over to getcarina.com and sign up for a free account – only takes a few seconds. Once you create your account, you’ll pretty much immediately see this:
Select a name to describe your cluster and click ‘Create Cluster’:
Your cluster will take a few seconds to build, and then should be active.
Download the zipfile provided – this contains everything you need to get started. First, unzip the file:
$ mkdir carina_deployment && cd carina_deployment $ unzip ~/Downloads/my_new_test_cluster.zip Archive: /Users/erik/Downloads/my_new_test_cluster.zip extracting: my_new_test_cluster/ca.pem extracting: my_new_test_cluster/README.md extracting: my_new_test_cluster/ca-key.pem extracting: my_new_test_cluster/docker.cmd extracting: my_new_test_cluster/docker.env extracting: my_new_test_cluster/docker.ps1 extracting: my_new_test_cluster/cert.pem extracting: my_new_test_cluster/key.pem
Next, configure your Docker environment, using the provided environment file:
$ source my_new_test_cluster/docker.env
Now our Docker environment is configured, let’s check it out:
$ docker info Containers: 5 Images: 4 Role: primary Strategy: spread Filters: affinity, health, constraint, port, dependency Nodes: 1 ab17f61d-9b19-402b-800d-ab935d5afe3b-n1: 22.214.171.124:42376 └ Containers: 5 └ Reserved CPUs: 0 / 12 └ Reserved Memory: 0 B / 4.2 GiB └ Labels: executiondriver=native-0.2, kernelversion=3.18.21-1-rackos, operatingsystem=Debian GNU/Linux 7 (wheezy) (containerized), storagedriver=aufs CPUs: 12 Total Memory: 4.2 GiB Name: c4873c9dd65d
We’ve now got a working Docker Swarm cluster! Let’s get an application running. I’ll start by grabbing an existing image from Docker Hub, which provides an Ubuntu environment, complete with Flask, Gunicorn, etc.
$ docker pull objectrocket/ubuntu_flask_python
4847681a-dcfc-44bd-84d3-66b67307fdb1-n1: Pulling objectrocket/ubuntu_flask_python:latest... : downloaded $ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE objectrocket/ubuntu_flask_python latest be574a6575a4 9 hours ago 370.8 MB
So now we’ve got an image; The only thing we need to do is give it credentials to our MongoDB instance, and it’s ready to do some work.
Let’s create a MongoDB instance in your ObjectRocket account. Log in to your account at https://app.objectrocket.com, and click on ‘Add Instance’:
We’ll select a simple “replica set” instance (not sharded), give it an easy-to-remember name “ErikTestReplicaSet”, and then click “Next”:
We’ll select a 2.6.10 instance, 5GB, in the IAD zone:
Now review, and click ‘Create’:
Now you’ve got a MongoDB instance! Your instances list should look like this:
Now there’s one thing left – give yourself access to your instance. You’ll need to do two things, first, add a user. Click on your instance, and then click on ‘+ Instance User’. Then you’ll define a login and password:
Next, you’ll need a network ACL as well. Refer to a few steps back when we checked the output of ‘docker info’ – you’ll see that our public IP is:
Nodes: 1 ab17f61d-9b19-402b-800d-ab935d5afe3b-n1: 126.96.36.199:42376
Simply add an ACL to allow this node access:
And that’s all there is to it. Let’s fire this thing up and see what happens.
$ echo "MONGO_URI=mongodb://OurTestUser:ArealGOODpassword@iad1-c12-1.objectrocket.com:50005,iad1-c12-0.objectrocket.com:50005/DATABASE" > myapp.env
$ docker run -d --env-file=myapp.env -P objectrocket/ubuntu_flask_python
Your container should be running – let’s check:
$ docker ps --latest 5aa9159675f7 objectrocket/ubuntu_flask_python gunicorn app:app -w About a minute ago Up About a minute 188.8.131.52:32768->8080/tcp 4847681a-dcfc-44bd-84d3-66b67307fdb1-n1/reverent_kare
Looks good. Let’s check the logs and make sure Gunicorn is up and healthy:
$ docker logs 5aa9159675f7 [2015-11-17 00:34:24 +0000]  [INFO] Starting gunicorn 19.3.0 [2015-11-17 00:34:24 +0000]  [INFO] Listening at: http://0.0.0.0:8080 (1) [2015-11-17 00:34:24 +0000]  [INFO] Using worker: sync [2015-11-17 00:34:24 +0000]  [INFO] Booting worker with pid: 9 ...
Now, let’s check our port mapping to see how to connect to it via the Internet:
$ docker port 5aa9159675f7 8080/tcp -> 184.108.40.206:32768
Our webserver, running on the (non-privileged) port tcp/8080, has been NAT’ed to the public address http://220.127.116.11:32768.
That’s all there is to it – you’re up and running with a high performance database ready to do some work. Where do you go from here? Simple, modify this container, add your own code, your own modules, your own management pieces, and make it your own! The flexibility of Docker makes it trivial and fun to extend your environment, and MongoDB is a great way to manage your data!
Resource Links – Try this at home!
Any questions? Don’t hesitate to ask, we’re happy to help. Thanks for reading!