Deploying a Rails App to the Dokku server

Tram Ho

Introduce

There are many different ways to deploy a Rails application, and there are many platforms and tools that support this. One of those ways is to deploy the rails application on a server with Dokku installed that I often use for small and medium customers at TakeIT Vietnam. This article will provide a brief overview of Dokku and how to easily deploy a Rails application to a server with Dokku installed.

What is Dokku?

If you must briefly like Dokku, you can describe Dokku as an open source Platform as a Service project that replaces Heroku. Dokku leverages the power of Docker to be deployed on a wide range of hardware and on low-cost servers. You have complete control over your server and enjoy the same outstanding features as Heroku. In addition, Dokku supports a lot of plugins to help you deploy more applications.

Deploying a Rails App

Deploying a Rails application to the Dokku server is simple. First, you will need to install CLI Dokku, which is a command line interface for managing and deploying applications. Once installed, you can use the CLI to deploy your application by creating a Dokku application and then pushing your code onto the application. Let’s go step by step.

  1. Minimum configuration requiredA newly installed operating system according to the list below:

    The server has one of the following architectures:

    • AMD64 (alternatively known as x86_64 ), commonly used for Intel cloud servers
    • ARMV7 (alternatively known as armhf ), commonly used for Raspberry PI
    • ARMV8 (alternatively known as arm64 ), commonly used for Raspberry PI and AWS Graviton

    To avoid server overload and unexpected errors during use:

    • Server needs at least 1GB of Ram
      • If the server is less than 1GB Ram then create a swap for your server :

    Finally a domain name, this is optional. However, using a domain name makes your application more accessible than just an IP address.

  2. Install Dokku on the serverInstall Dokku using the bootstrap file

    Set up SSH keys and VirtualHost

  3. Deploying a Rails applicationAfter completing the installation of Dokku on the server, we will start deploying a basic rails application by following these steps:

    In this example, we will use the Heroku Ruby on Rails “Getting Started” app repo for deployment.

    Clone source code from git repository to server.

    Create an app on Dokku

    By default, Dokku will not provide pre-installed databases that we have to install through Plugins. You can access the list of available Plugins from the Dokku homepage , here I will be using Postgres so I will install the Postgres plugin provided from Dokku

    Create a new database

    Link the previously created application with the newly created database.

    By linking the application and the database, Dokku will create an environment variable of DATABASE_URL on the Dokku application.

    Deploy the ruby-getting-started app to the Dokku server. All you need to do is add the remote to git and push the source code to the Dokku git repository.

    After running git push dokku main:master command, you will get ouput almost like below.

summary

Installing a Rails application on a Dokku server is a great way to quickly and easily deploy an application. With a few commands, you’ve got your application up and running in no time. In addition to the simple commands above, Dokku can do more with advanced configurations, plugins provided by Dokku and the community also make Dokku more flexible and extensible.

Dokku has advantages but at the same time also has disadvantages, hope you will like and wait for upcoming Dokku related articles.

Share the news now

Source : Viblo