14
.
11
.
2023
14
.
11
.
2018
Ruby on Rails
Backend
Tutorial

Docker hosted on Jelastic

Marcin Prokop
Ruby Developer

Two years ago we introduced Docker to our company. One of our projects was complex in terms of deployment architecture and scalability. We were looking for a solution which allows us to simplify the process of deployment and scaling client's instances in the future. Docker turned out as a very good tool to isolate apps into containers with all needed dependencies and treat them as block boxes. They are easily portable from machine to machine and basically, we can host them whenever we want if there Docker engine is installed. I think it doesn't make sense describing Docker more, because there are already a lot of articles about it, not to mention excellent Docker documentation.

The next question was: where to host our docker containers? There were various options from dedicated servers to PaaS solutions. As a company, we don't deal with server management and prefer using Heroku for our apps. That's why we looked more closely at solutions that do not require care of the servers. After long research, we decided to go with Jelastic.

In few words, Jelastic is a complex dev platform which combines Platform as a Service (PaaS) and Container as a Service cloud models. It supports deployment for many technologies, including Python, Java, PHP and Docker as well. With automatic scalability based on pay-as-you-go model you don't have to care about resources management. Moreover Jelastic came with rich API which is helpful to automate many things outside of their panel. For more information about this platform, I recommend visit this post.

Image from jelastic.com

In this article I will show how to simply deploy dockerized Rails app. Let's start with the simple Docker image for Rails. I assumed that we have a Rails app which uses an external database (e.g. Postgresql) and has generated scaffold for posts (title and body).

FROM ruby:2.5.1

RUN apt-get update -qq \
   && apt-get install -y --no-install-recommends \
   libpq-dev \
   git \
   nodejs \
   vim \
   && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY Gemfile .
COPY Gemfile.lock .

RUN bundle install --without test development
COPY . .

RUN chmod +x docker/launch.sh

CMD ./docker/launch.sh

We are not doing much in this Dockerfile, just installing necessary libs, copy project files, install gems and finally run the application. Also I like put docker things in docker directory. Let's build it.

docker build -t b4k3r/sample-app .

And push to the registry (can be a Docker or private). Later Jelalstic will fetch the image from this registry to run the app.

docker push b4k3r/sample-app

Let's move to Jelastic part. The first thing we need to do is create an environment. The environment in Jelastic is like a private space or an independent virtual machine for your application environment. In the environment, among other things, you can put environment variables, define volumes or adjust resources for your app. As you can see, there is also vertical and horizontal scaling. In the vertical scaling, you can adjust resources like ram, CPU by cloudlets. Cloudlet is the unit which represents a specific amount of RAM and CPU clocking. Below, on the right side system automatically calculates estimation cost.

After clicking "Select container" we can find and select our image which was previously built and pushed.

Of course, if we store Docker images on a different repository, we can have access to them through Jelastic as well. Let's do the same for the database image.

Now we have defined two containers. Let's move to links and environment variables part. Just like in Docker, Jelastic allows defining a connection between containers of a single environment aka links and environment variables.

Jelastic automatically adds some default environment variables to containers.

We can't forget about volumes which are useful to prevent losing dynamic data in containers. Jelastic supports it as well, even remote storage!

Basically, that's it. We configured production environment for our simple Rails app.

Conclusion

In our project we haven't used many features which Jelastic offers. What interested us, were Docker support and no server management. Did Jelastic do job? Quite good but there were some issues with stability, for example with disappearing environment variables after redeploying containers. Despite this, support from Jelastic team was excellent (I hope now also :) ) and guys was fixing issues as soon as possible. In the next article I will write how we created complex deployment architecture using Jelastic, Docker and Jekins.

Marcin Prokop
Ruby Developer

Check my Twitter

Check my Linkedin

Did you like it? 

Sign up To VIsuality newsletter

READ ALSO

N+1 in Ruby on Rails

14
.
11
.
2023
Katarzyna Melon-Markowska
Ruby on Rails
Ruby
Backend

Turbo Streams and current user

29
.
11
.
2023
Mateusz Bilski
Hotwire
Ruby on Rails
Backend
Frontend

Showing progress of background jobs with Turbo

14
.
11
.
2023
Michał Łęcicki
Ruby on Rails
Ruby
Hotwire
Frontend
Backend

Table partitioning in Rails, part 1 - Postgres Stories

14
.
11
.
2023
Jarosław Kowalewski
Postgresql
Backend
Ruby on Rails

Table partitioning types - Postgres Stories

14
.
11
.
2023
Jarosław Kowalewski
Postgresql
Backend

Indexing partitioned table - Postgres Stories

14
.
11
.
2023
Jarosław Kowalewski
Backend
Postgresql
SQL Views in Ruby on Rails

SQL views in Ruby on Rails

14
.
11
.
2023
Jan Grela
Backend
Ruby
Ruby on Rails
Postgresql
Design your bathroom in React

Design your bathroom in React

14
.
11
.
2023
Bartosz Bazański
Frontend
React
Lazy Attributes in Ruby - Krzysztof Wawer

Lazy attributes in Ruby

14
.
11
.
2023
Krzysztof Wawer
Ruby
Software

Exporting CSV files using COPY - Postgres Stories

14
.
11
.
2023
Jarosław Kowalewski
Postgresql
Ruby
Ruby on Rails
Michał Łęcicki - From Celluloid to Concurrent Ruby

From Celluloid to Concurrent Ruby: Practical Examples Of Multithreading Calls

14
.
11
.
2023
Michał Łęcicki
Backend
Ruby
Ruby on Rails
Software

Super Slide Me - Game Written in React

14
.
11
.
2023
Antoni Smoliński
Frontend
React
Jarek Kowalewski - ILIKE vs LIKE/LOWER - Postgres Stories

ILIKE vs LIKE/LOWER - Postgres Stories

14
.
11
.
2023
Jarosław Kowalewski
Ruby
Ruby on Rails
Postgresql

A look back at Friendly.rb 2023

14
.
11
.
2023
Cezary Kłos
Conferences
Ruby

Debugging Rails - Ruby Junior Chronicles

14
.
11
.
2023
Piotr Witek
Ruby on Rails
Backend
Tutorial

GraphQL in Ruby on Rails: How to Extend Connections

14
.
11
.
2023
Cezary Kłos
Ruby on Rails
GraphQL
Backend
Tutorial

Tetris on Rails

17
.
03
.
2024
Paweł Strzałkowski
Ruby on Rails
Backend
Frontend
Hotwire

EURUKO 2023 - here's what you've missed

14
.
11
.
2023
Michał Łęcicki
Ruby
Conferences

Easy introduction to Connection Pool in ruby

14
.
11
.
2023
Michał Łęcicki
Ruby on Rails
Backend
Ruby
Tutorial

When crazy ideas bring great time or how we organized our first Conference!

04
.
12
.
2023
Alexander Repnikov
Ruby on Rails
Conferences
Visuality

Stacey Matrix & Takeaways - why does your IT project suck?

14
.
11
.
2023
Wiktor De Witte
Project Management
Business

A simple guide to pessimistic locking in Rails

14
.
11
.
2023
Michał Łęcicki
Ruby on Rails
Backend
Ruby
Tutorial

Poltrax design - story of POLTRAX (part 3)

04
.
12
.
2023
Mateusz Wodyk
Startups
Business
Design

Writing Chrome Extensions Is (probably) Easier Than You Think

14
.
11
.
2023
Antoni Smoliński
Tutorial
Frontend
Backend