Using Dokku for rails applications on a Linode Server.
This is a step by step guide to configure Dokku on a Linode server. For more details visit Dokku docs, please.
What is Dokku?
Dokku is an open source platform as a service that runs a single server, similar to Heroku. Click here to visit their website.
Configure your VPS on a Linode server.
Some configurations are required in order to achieve a better performance in Dokku. The configurations are:
- Open your server’s dashboard in the Linode Manager.
- Make sure your Linode is using KVM, not Xen, for virtualization.
- In the “Rebuild” tab, select “Ubuntu 14.04 LTS”, set a root password, and rebuild.
- Once your Linode has been created, click “Boot” and wait for it to complete.
- SSH into your server as root and run the following commands:
- When prompted, install Grub into the first hard drive.
apt-get updateapt-get -qq upgradeapt-get install linux-image-virtual linux-image-extra-virtual
- Back in your server’s dashboard, click “Edit” on its Configuration Profile
- Change the “Kernel” option to “GRUB 2” and save your changes.
- Lastly, reboot the Linode.
This changes are necessary because of Docker has a better performance with AUFS.
Install Dokku.
To install Dokku, access your Linode using ssh and run the following commands:
wget https://raw.githubusercontent.com/dokku/dokku/v0.7.2/bootstrap.shsudo DOKKU_TAG=v0.7.2 bash bootstrap.sh
After installing Dokku, you should configure the ssh access and the virtualhosts in order to respectively deploy and access your app through a browser. Open your browser and enter the IP address of your Linode. There are a few parts that you need to configure here. See the following images.
In your terminal run the following command:
cat ~/.ssh/id_rsa.pub
If you want to use a subdomain, check the option 'Use virtualhost naming for apps'.
Create a new dokku application
In order to create a new application in the Dokku, it is necessary to access your server via ssh and run the following command:
dokku apps:create <app-name>
Install Postgres plugin
By default Dokku don’t come with a database. Therefore, we’ll need to install a plugin to work with Postgres or MySQL. Let’s stick with Postgres, run the following command to install the plugin:
sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git
Run the following command to create a new service. It is necessary fill the service name, but it is not necessary to use the same app name. Create a new services with name, not necessary some name your app. Run the command:
dokku postgres:create <serviceapp-name>
Access your server to link the postgres service to your app. Run the following command:
dokku postgres:link <service-name> <app-name>
List of commands to postgres plugin
postgres:clone <name> <new-name> Create container <new-name> then copy data from <name> into <new-name>postgres:connect <name> Connect via psql to a postgres servicepostgres:create <name> Create a postgres service with environment variablespostgres:destroy <name> Delete the service and stop its container if there are no links leftpostgres:enter <name> [command] Enter or run a command in a running postgres service containerpostgres:export <name> > <file> Export a dump of the postgres service databasepostgres:expose <name> [port] Expose a postgres service on custom port if provided (random port otherwise)postgres:import <name> < <file> Import a dump into the postgres service databasepostgres:info <name> Print the connection informationpostgres:link <name> <app> Link the postgres service to the apppostgres:list List all postgres servicespostgres:logs <name> [-t] Print the most recent log(s) for this servicepostgres:promote <name> <app> Promote service <name> as DATABASE_URL in <app>postgres:restart <name> Graceful shutdown and restart of the postgres service containerpostgres:start <name> Start a previously stopped postgres servicepostgres:stop <name> Stop a running postgres servicepostgres:unexpose <name> Unexpose a previously exposed postgres servicepostgres:unlink <name> <app> Unlink the postgres service from the app
Deploying your app
In order to deploy your app you will need to add a remote link.
git remote add dokku dokku@ip-or-domain:<app-name>
After that you can deploy your app with git push, for example:
git push dokku master
To run any rake, it is necessary that you access your server via ssh and run the following commands:
dokku run <app-name> rake <rake-task>
That’s all folks! Your application is up and running on a Linode Server.
References