Recently, dotCloud, a popular PaaS releases software which powers their infrastructure named “Docker”. It is very interesting and promising project.
Docker is basically a tool to manage LXC Linux containers, check out docker.io for more details. It provides fast and lightweight userspace for the linux kernel (as opposed to heavy weight Virual Machine implementation). In my visual perspective: Docker > LXC > Chroot
At the mean time there is a project named “Dokku” which tries to implement Heroku-like PaaS. And this article is about how to deploy Rails 4 using Dokku. I’m running Ubuntu 13.04 and let’s start installing Dokku. Just grab the stable version
wget -qO- https://raw.github.com/progrium/dokku/v0.2.3/bootstrap.sh | sudo DOKKU_TAG=v0.2.3 bash
It’s 0.2.3 at the time of writing, Add new SSH config, edit ~/.ssh/config
Host server-ip HostName server-ip User git IdentifyFile ~/.ssh/id_rsa
Inside your project, add new remote
git remote add dokku dokku@server-ip:subdomain-or-appname
Then, add permission for your machine, so that you can git push to new remote
cat ~/.ssh/id_rsa.pub | ssh user@server-ip “sshcommand acl-add dokku user”
Install relavant plugins, in this case is showing how to install Postgresql plugin
cd /var/lib/dokku/plugins git clone https://github.com/Kloadut/dokku-pg-plugin postgresql && cd postgresql ./install
After postgresql plugin installed, you can create the database by
dokku postgresql:create db-name
At this point, you are ready to deploy. Step inside your project and run
git push dokku master
And link database to the app
dokku postgresql:link app-name db-name
Restart nginx if needed.
If you use Procfile for the project and have worker job, you might want to check shoreman in order to start. Since current dokku will only start ‘web’ process type.
git clone https://github.com/statianzo/dokku-shoreman.git /var/lib/dokku/plugins/dokku-shoreman
On the next deploy, it will start worker process type as well.
In case your application have files upload functionality to local file system, you might find dokku persisten-storage plugin useful.
git clone https://github.com/dyson/dokku-persistent-storage.git /var/lib/dokku/plugins/persistent-storage
You can mount a host directory as a container volume. For example, in your server
cd /home/dokku mkdir -p shared/system
touch /home/dokku/<app-name>/PERSISTENT_STORAGE echo “/home/dokku/shared:/app/public:rw” > /home/dokku/<app-name>/PERSISTENT_STORAGE
Now your container will have mount point to host writable file system. Therefore, the app stores statics files in container /app/public but writes to /home/dokku/shared/system on host filesystem.
- If you’d like to have your app available on your subdomain make sure your hostname match with your app name and
/home/dokku/VHOSTcontains your domain name.
- Use docker commands such as
docker images` are very useful command to trace some problems. I have created an uninstall script https://gist.github.com/zdk/10004901 for convenience while testing.