Create your own PaaS with Dokku
Ever get frustrated with a deployment solution on a VPS using something like Capistrano and you can’t use Heroku because of client restrictions?
Dokku gives you Heroku-like functionality that can be deployed to any number of VPS providers.
Let’s use Vagrant with Dokku so we can just test Dokku out on our local machine.
Requirements for OS X:
- Virtualbox: https://www.virtualbox.org/
- Vagrant: https://www.vagrantup.com/
- Dokku: https://github.com/progrium/dokku
- Add the following to your /etc/hosts (you’ll have to use sudo):
10.0.0.2 dokku.me
10.0.0.2 rails.dokku.me
10.0.0.2 js.dokku.me
2. Clone the Dokku repository:
git clone git@github.com:progrium/dokku.git
3. Change to the Dokku directory:
cd dokku
4. Bring up the Vagrant virtual machine (takes a few minutes):
vagrant up
5. Add the correct permissions for the Dokku user:
cat ~/.ssh/id_rsa.pub | ssh root@dokku.me sudo sshcommand acl-add dokku onnimonni
6. Browse to http://dokku.me to setup your install:
- Your public key should be auto-populated in the ‘Public Key’ section.
- Change the hostname to dokku.me
- Check ‘Use virtualhost naming for apps’
- Click ‘Finish Setup’
7. Let’s use Heroku’s Node.js sample project:
git clone git@github.com:heroku/node-js-sample.git
cd node-js-sample
git remote add dokku dokku@dokku.me:js
git push dokku
8. Navigate to http://js.dokku.me/ and you should see “Hello World!”
9. Now let’s add Heroku’s Rails sample project now:
10. First install the Postgres Dokku plugin:
ssh root@dokku.me
cd /var/lib/dokku/plugins
git clone https://github.com/jeffutter/dokku-postgresql-plugin postgresqldokku plugins-install
11. Start Postgres:
ssh dokku@dokku.me postgresql:start
12. Clone the Heroku Rails example:
git@github.com:heroku/ruby-rails-sample.git
git remote add dokku dokku@dokku.me:rails
git push dokku
13. When you ssh using the Dokku user it functions similar to the Heroku toolbelt:
ssh dokku@dokku.me
14. Now run the following to create a Postgres database and run your migration:
ssh dokku@dokku.me postgresql:create rails
ssh dokku@dokku.me run rails rake db:migrate
Browse to http://rails.dokku.me/ and you should have a working Rails app!