Deploy your code on DreamHost cloud servers using Dokku, a small Platform As A Service implementation built on Docker. With Dokku running on your instance, you can push code directly from your local machine running git and see it running on a production server. This tiny PaaS implements Heroku’s buildpack specification allowing to run software written in PHP, Golang, NodeJS, Python, and Ruby (including Ruby on Rails). We love it at DreamHost because what’s not to love in a “Docker-powered mini-Heroku in around 200 lines of Bash”?
This tutorial will show you how to install Dokku in one step on a single DreamHost Cloud server running Ubuntu 14.04LTS, using a cloud-init script.
Create a new server
The first step: decide the full domain name for the new server so that Dokku can work at its best. For this tutorial, we’ll use apps.example.com.
$ source openrc.sh $ openstack server create --image Ubuntu-16.04 --flavor gp1.semisonic --security-group default --key-name $YOUR_SSH_KEYNAME --user-data dokku-cloudinit.sh my-dokku-server
It’s also possible to use the web UI, feeding the content of dokku cloud-init script in the Post-Creation tab as Customization Script Source.
The cloud-init script simply adds the APT repositories for Docker and Dokku, the respective PGP keys. Then it installs Dokku from the official packages, setting the values of some important variables like the full qualified domain name of the new server, apps.example.com in this case.
In 30 seconds the server boots: get its IP address and create DNS records for the domain. You’ll need to register two A records: one for apps.example.com, and a wildcard record *.apps.example.com—both pointing to the new instance’s IP address.
Now it’s time to push Heroku-like apps to your shiny new PaaS. Unless you already have one in mind, let’s use a simple node.js app, like this Workout Calendar Generator. Log in to the new server, apps.example.com, and prepare the Dokku environment:
[localhost]$ ssh firstname.lastname@example.org [email@example.com]$ dokku apps:create workout # the name of the app [firstname.lastname@example.org]$ exit
On your local machine clone the repository, add a remote to the DreamCompute server and push the code:
[localhost]$ git clone git://github.com/clee/p90xcalgen [localhost]$ git remote add dokku email@example.com:workout # the same name used in the dokku command before [localhost]$ git push dokku master
If all went well and the DNS records propagated correctly, you should be able to see the Calendar Workout app running at the domain name you used (i.e. http://workout.apps.example.com).
Dokku combined with DreamHost cloud servers makes for a great little tool to quickly iterate and experiment with running code with very little overhead. We hope this has helped you!
Have questions, or want to start a conversation about this? Leave a comment below, or feel free to discuss here!