Deploy a Ruby on Rails application on Koyeb and benefit from Koyeb native autoscaling, automatic HTTPS (SSL), auto-healing, and global load-balancing across our edge network with zero configuration.
This guide explains how to deploy a Ruby on Rails application on Koyeb using:
To successfully follow this documentation, you will need to have a Koyeb account. You can optionally install the Koyeb CLI if you prefer to follow this guide without leaving the terminal.
You can deploy and preview the sample Ruby on Rails application that we will run on Koyeb in this guide using the Deploy to Koyeb button below.
You can access the repository used for this documentation here.
Get started by creating a minimalistic Rails application that we will deploy on Koyeb. You will need Ruby and Rails installed on your machine.
In your terminal, run the following commands to create a new Rails application:
$ rails new example-rails --minimal
This will create a new minimum Rails application skeleton in the
example-rails directory with just Active Record, Action Pack, Active Support, Railties, and the bare necessity support gems.
Create a new Rails controller by running the following command:
rails generate controller HelloKoyeb index
Then, open the
config/routes.rb file and edit as shown below to indicate Rails GET
/ requests are mapped to the index action of the HelloKoyeb controller.
Rails.application.routes.draw do get 'hello_koyeb/index' + root 'hello_world#index' # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html # Defines the root path route ("/") # root "articles#index" end
Launch the application locally to make sure everything is running as expected.
cd example-rails rails server
You can now access the application at
rails new command we ran previously initialized a new git repository in the
We will use this repository to version the application code and push the changes to a GitHub repository. If you don't have an existing GitHub repository to push the code to, you can create a new one and run the following commands to commit and push changes to your GitHub repository:
git add . git commit -m "Initial commit" git remote add origin firstname.lastname@example.org:<YOUR_GITHUB_USERNAME>/<YOUR_REPOSITORY_NAME>.git git push -u origin main
To deploy the Rails app on Koyeb using the control panel, follow the steps below:
A Koyeb App and Service have been created. Your application is now going to be built and deployed on Koyeb. Once the build is complete, you will be able to access your application running on Koyeb by clicking the URL ending with
To deploy the Rails app on Koyeb using the Koyeb CLI, run the following command in your terminal:
koyeb app init example-rails \ --git github.com/<YOUR_GITHUB_USERNAME>/<YOUR_REPOSITORY_NAME> \ --git-branch main \ --ports 8080:http \ --routes /:8080 \ --env PORT=8080
Make sure to replace
<YOUR_GITHUB_USERNAME>/<YOUR_REPOSITORY_NAME> with your GitHub username and repository name.
To track the app deployment and visualize build logs, execute the following command:
koyeb service logs example-rails/example-rails -t build
Once the deployment of your application has finished, you can retrieve the public domain to access your application by running the following command:
$ koyeb app get example-rails ID NAME DOMAINS CREATED AT 55d75993 example-rails ["example-rails-myorg.koyeb.app"] 20 Sep 22 09:55 UTC
With your app running, you can track the runtime logs by running the following command:
koyeb service logs example-rails/example-rails -t runtime
Alternatively to using git-driven deployment, you can deploy a pre-built container from any public or private registry. This can be useful if your application needs specific system dependencies or you need more control over how the build is performed.
To dockerize the Rails application, create a
Dockerfile in your project root directory and copy the content below:
FROM ruby:3-alpine WORKDIR /app COPY . . RUN gem install bundler RUN bundle install ENV RAILS_ENV=production RUN bundle exec rails assets:precompile EXPOSE 3000 CMD ["rails", "server", "-b", "0.0.0.0"]
The Dockerfile above provides the minimum requirements to run the Rails application. You can easily extend it depending on your needs.
To build and push the Docker image to a registry and deploy it on Koyeb, refer to the Deploy an app from a Docker image.