How to Dockerize Rails Application: Compose and Rails Tutorial
Introduction
A curious developer and tech enthusiast never miss an opportunity to learn a little more every day! I can absolutely relate to this urge to learn. So, keeping your curiosity in mind, we are back with another Rails tutorial on how to dockerize rails applications with the help of Docker Compose. Hoping that you are familiar with what is Docker and why do we need Docker.
Let’s get started with the app development and dockerizing it.
Create a Rails App
Fire the following commands to create a rails app.
Prerequisites: Dockerize Rails Application
As we are implementing Docker Compose, make sure about the following installations before getting started.
Install Docker Community Edition
Install Docker Compose
Create a Dockerfile
The Dockerfile is the foundation of any Dockerized app. It contains all the instructions for building the application image. You can set this up by installing Ruby and all of its dependencies. The Dockerfile consists of the following instructions.
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
✓ Live Streaming✓ Interactive Chat✓ Private Shows✓ HD Quality
Anya is LIVE right now
FREE
Free to watch • No registration required • HD streaming
Michael Hartl's Ruby on Rails 4.0 Tutorial - @mhartl @railstutorial #ruby #rails #ror
Ruby on Rails, even eight years after its first release, is still recognized as one of the best frameworks for Web applications for many reasons, not the least of which are its cost (it’s free) and its scalability (sites as big as Twitter have used it).
Rails 4.0 was released last year, and soon after, Michael Hartl updated his famous Rails Tutorial.
For the past three weeks now, I've been working with a friend on a new website for a local restaurant. It's my first actual client work. It's been challenging, educational, fun...and time-consuming.
Not wanting to stray from my Weekly Website project, not wanting slow down on the restaurant site, and not wanting to quit my job for extra time and put my family on the street, I realized that something had to give. I needed a project that would be valuable to me but wouldn't take a ton of time.
That's why I decided to work through Michael Hartl's Rails Tutorial again.
I worked through this book once before, last fall. It was my first taste of development, and I didn't really understand much of what was going on. I think the only concept I fully understood after the first time through was using .erb templates with a layout.
Working through the tutorial a second time, I learned a lot more:
- After working with mostly Sinatra, Rails seems like cheating. So much stuff happens automagically. I'm wary of getting sucked into Rails before I really understand what it's doing, first.
- I finally became comfortable with using and setting up a postgrsql database.
- TDD is also making a lot more sense. I need to start doing that.
That's it for now. I'll have another post up for this week shortly.
Rspec und Capybara problems with the Michael Hartl's Rails tutorial
So I am working thorugh Michael Hartl's video tutorial on Ruby on Rails (http://railstutorial.org). The tutorial is a bit older using Rails 3.2 and Ruby 1.9 (I believe) and some older gems.
I am working with the current versions of Rails 4.0 and ruby 2.0. So I came to the point where he is testing the titles of some pages with Rspec and it would not work. I searched a long time for reasons these test are failing.
Turns out Capybara doesn't test for object that are not visible on the page anymore. And a link further it tells me about some workarounds and that the new Capybara has a method for testing page titles. So update to Capybara 2.1.0 (from 1.1.2)...
Apparently in Capybara 2.x some things have changed and the "visit" method in the test is suddenly undefined.
Solution is to move the static_pages_spec.rb from spec/requests folder to spec/features and include the following line of code in spec_helper.rb:
#insert after "RSpec.configure do |config|"
config.include Capybara::DSL, :type => :feature
So its always a natural feeling when you want to start blogging so badly but can't think of anything/where to start off. Following the thought i ended up deciding that i'm gonna blog almost anything that comes in my mind.
Its 9ish and dinners about to be served. Started my first chapter from railstutorial. Seems to be a good resource if your just starting out programming from a long break( that i'm ) and willing to learn something as new and good as Rails.
The stable version for ruby to be used in tutorial is 1.9.x. I googled up how to update ruby? ( i didn't knew command ) so ended up with this tool called RVM lets see what in box there?Â
Whilst thats installing i read something about David Heinemeier Hansson. Seems an interesting guy. An all-rounder i guess. Followed on twitter.Â
The next step is to install GIT an awesome version control.Â
RVM is ruby version manager that lets us manage different ruby version on same system. It is highly depended on macports. So if your having trouble make sure you install command line tools as pre-requisite. The link here is static download because that helps if you have a slow internet.Â
One of the dependency that RVM survives on is libksba, thats some nasty library that took me forever to get started. Make sure to install by,
port install libska
Later after install Rails with a specific version i.e. 3.2.13 in my case. Note that even gems are version specific. And your done.Â
Issue the following command to create a new rails project.
rails new < project_name >
The above command does bundling for you which we will customise as per our requirement. Customisation really mean to stick to specific version of the gems so that things don't break. ( I'm referring the above mentioned tutorial. ). So that's it i guess, we are ready to see our app running. Issue following command to start out Rails server. This is local to your native development environment. Â
rails server
This enables us to see our app up and running on localhost:3000.Â
Thereafter setup GIT and add logs, dsstore ( mac ), sqlite etc to gitignore file. Commit the files as Initial commit. Now we might be wondering why are we using GIT that's because it keeps track of our effort. That means it keeps record of all our files. In most of case things are really prone human error. Thus if we ever accidentally delete any file that was important we can always recover it back using this lil too GIT.Â
I'm using Github to save my progress as a remote repo hosting. The following learning project is located at master branch here. So later after init commit. I'll be doing deployment of our null app. Heruku is the the preferred platform i'll be using. Since it uses postgres adding the following gem is quite reasonable. Later after doing that changes to the Gemfile we need to run again bundle install w/ a production parameter.
bundle install --without production
This is to update the gemlock that is used by heroku internally.
Heroku deploy is easy all you need is an heroku account. Setup Heroku Toolbelt. Thats pretty much it. Next is navigating to app root directory and running heroku create and git push respectively. Thereafter the app is running live on generated url.
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
✓ Live Streaming✓ Interactive Chat✓ Private Shows✓ HD Quality
Anya is LIVE right now
FREE
Free to watch • No registration required • HD streaming