SlideShare a Scribd company logo
HOW TO
DOCKERIZE
RAILS
APPLICATION
: COMPOSE
AND RAILS
TUTORIAL


https://www.bacancytechnology.com/
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.


mkdir ~/projects/noteapp
cd ~/projects/noteapp
Prerequisites:
Dockerize
Rails
Application
Install Docker Community Edition
Install Docker Compose
As we are implementing Docker Compose,
make sure about the following installations
before getting started.
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.
FROM ruby:2.3.0
RUN apt-get update -qq && apt-get
install -y build-essential libpq-dev nodejs
RUN mkdir /noteapp
WORKDIR /noteapp
ADD Gemfile /noteapp/Gemfile
ADD Gemfile.lock /noteapp/Gemfile.lock
RUN bundle install
ADD . /noteapp
// Dockerfile
Dockerfile will keep the app code inside
an image, building a container with
Bundler, Ruby, and other dependencies.
Therefore in the root directory of the
application, create a new Dockerfile using
the command touch Dockerfile and put
the content of the above dockerfile inside
it.
Explanation
FROM ruby:2.3.0: Tells Docker to use
the prebuilt Ruby image. There are
several choices, but this project uses
the ruby:2.3.0 image.
RUN: To run commands. Here, RUN is
for installing different software pieces
with Apt.
WORKDIR: For stating the base
directory from where all the
commands are executed.
ADD: For copying files from the host
machine to our container.
Create a
Gemfile
Next, open the editor and create a
bootstrap Gemfile that loads Rails.
source 'https://rubygems.org'
gem 'rails', '~>5.0.0'
Create an empty Gemfile.lock file to build
our Dockerfile.
touch Gemfile.lock
// gemfile
Dockerize Rails App: Add
Portability, Modularity, and
Scalability to your app
Contact Bacancy and hire Rails developer to
dockerize your rails application.
Define
Services
Using Docker
Compose
Finally, moving towards the most important
section. The docker-compose.yml file will
consist of services needed for your app (web
application and DB), for getting each other’s
Docker image, and the config for connecting
them and making it visible on the port.
version: '2'
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD:
password
MYSQL_DATABASE: noteapp
MYSQL_USER: appuser
MYSQL_PASSWORD: password
// docker-compose.yml
ports:
- "3307:3306"
app:
build: .
command: bundle exec rails s -p 3000 -b
'0.0.0.0'
volumes:
- ".:/noteapp"
ports:
- "3001:3000"
depends_on
- db
links:
- db
Build the
Project
Now build the skeleton of the rails
application with the help of docker-
compose run.


docker-compose run app rails new . --force
--database=mysql
compose– builds the image for the app
service, which we have to define inside
our docker-compose.yml
runs rails new – using that image it runs
the app inside a new container
database=mysql– to define the database
Your application should be created after the
command is successfully executed. List the
files using ls -l
Database
Connection
In this section, we will connect the database
as rails wants a database to be running on
the localhost.


We will also alter the database and
username for aligning it with the defaults
by the MySQL image. When we run the
docker-compose command first, it will
create a DB container that downloads the
MySQL database image and creates a DB
based on the environment variables set in
the docker-compose.yml file.


By now, we have a database container, and
app structure created. We need to edit the
config/database.yml file and set the
configurations from the environment
variables.


Replace the contents of config/database.yml
with the following:
version: '2'
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: noteapp
MYSQL_USER: appuser
MYSQL_PASSWORD: password
ports:
- "3307:3306"
app:
build: .
command: bundle exec rails s -p 3000 -b
'0.0.0.0'
// docker-compose.yml
volumes:
- ".:/noteapp"
ports:
- "3001:3000"
depends_on:
- db
links:
- db
environment :
DB_USER: root
DB_NAME: noteapp
DB_PASSWORD: password
DB_HOST: db
After setting up the docker-compose.yml,
run the docker-compose build command to
build an image for the app and install all the
required gems.
Run the below command for database
creation.


docker-compose run --rm app rake
db:migrate
Before creating any migrations/models, let’s
do a docker-compose up to start both app
and database services and boot the
application after making the changes in
database.yml.


We can see that rails is running on port
3000 in the container after the command is
successfully executed. But, that’s not the
port on the host, so we won’t be able to
access it on the browser. As per docker-
compose, we have exposed the port on the
localhost from 3000 to 3001; therefore, it
should be available on localhost:3001.
Once you are done with the app running on
the browser, create a model and perform
the migration using these commands in a
different console of the project directory.
docker-compose run --rm app rails g
scaffold note title body:text
docker-compose run --rm app rake
db:migrate
Now, we can access the application on port
3001- localhost:3001/notes and perform
actions on the application.
Summary:
How to
Dockerize
Rails
Application
mkdir ~/projects/noteapp
cd ~/projects/noteapp
Create Gemfile and empty Gemfile.lock
(content is given above)
Create Dockerfile (content is given
above)
Create docker-compose.yml (content is
given above)
docker-compose run app rails new . –
force –database=mysql
Make changes in config/database.yml
docker-compose build
docker-compose up
http://localhost:3001
docker-compose run –rm app rails g
scaffold note title body:text
docker-compose run –rm app rake
db:migrate
http://localhost:3001/notes


Watch the video tutorial on how to
dockerize rails application as well.
Source Code: dockerize-
rails-app
You can also clone the code and go through
the project. Here’s the source code of the
repository: dockerize-rails-app


Commands: Stop,
Restart, and Rebuild the
Application
To stop the application
docker-compose down
To restart the application
docker-compose up
To rebuild the application
Rebuilding the application is a must when
you’re trying different configs and altering
the Gemfile or Compose file.
➡Sometimes only docker-compose up –
build is enough.
➡But, if you want to rebuild the entire app
fully, then use docker-compose run app
bundle install, followed by docker-compose
up –build for synchronizing changes
between the Gemfile.lock and the host.
Conclusion
That’s it for the tutorial: how to dockerize
rails application using Docker compose. I
hope the tutorial was helpful to you for
building your own demo app and exploring
more.


Visit the Ruby on Rails tutorials page for
similar tutorials, where you can explore
your interests and play around with the
code. Looking for skilled rails developers
who can help you meet your project
requirements? Contact us and hire Rails
developer.
Thank You
www.bacancytechnology.com

More Related Content

What's hot (20)

Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and Rails
Wen-Tien Chang
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
peter_marklund
 
Utiliser Webpack dans une application Symfony
Utiliser Webpack dans une application SymfonyUtiliser Webpack dans une application Symfony
Utiliser Webpack dans une application Symfony
Alain Hippolyte
 
Asp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework CoreAsp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework Core
mohamed elshafey
 
Build Your Own CMS with Apache Sling
Build Your Own CMS with Apache SlingBuild Your Own CMS with Apache Sling
Build Your Own CMS with Apache Sling
Bob Paulin
 
TorqueBox
TorqueBoxTorqueBox
TorqueBox
bobmcwhirter
 
Java presentation
Java presentationJava presentation
Java presentation
Karan Sareen
 
Open Social Summit Korea
Open Social Summit KoreaOpen Social Summit Korea
Open Social Summit Korea
Arne Roomann-Kurrik
 
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSDeveloping Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Shekhar Gulati
 
Cooking Perl with Chef: Real World Tutorial with Jitterbug
Cooking Perl with Chef: Real World Tutorial with JitterbugCooking Perl with Chef: Real World Tutorial with Jitterbug
Cooking Perl with Chef: Real World Tutorial with Jitterbug
David Golden
 
Rails Engine Patterns
Rails Engine PatternsRails Engine Patterns
Rails Engine Patterns
Andy Maleh
 
MVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on RailsMVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on Rails
codeinmotion
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
Joshua Long
 
Laravel Restful API and AngularJS
Laravel Restful API and AngularJSLaravel Restful API and AngularJS
Laravel Restful API and AngularJS
Blake Newman
 
Why Laravel?
Why Laravel?Why Laravel?
Why Laravel?
Jonathan Goode
 
Advance java Online Training in Hyderabad
Advance java Online Training in HyderabadAdvance java Online Training in Hyderabad
Advance java Online Training in Hyderabad
Ugs8008
 
Aligning Ember.js with Web Standards
Aligning Ember.js with Web StandardsAligning Ember.js with Web Standards
Aligning Ember.js with Web Standards
Matthew Beale
 
Java servlets and CGI
Java servlets and CGIJava servlets and CGI
Java servlets and CGI
lavanya marichamy
 
Symfony Live 2018 - Développez votre frontend avec ReactJS et Symfony Webpack...
Symfony Live 2018 - Développez votre frontend avec ReactJS et Symfony Webpack...Symfony Live 2018 - Développez votre frontend avec ReactJS et Symfony Webpack...
Symfony Live 2018 - Développez votre frontend avec ReactJS et Symfony Webpack...
Alain Hippolyte
 
React Native in Production
React Native in ProductionReact Native in Production
React Native in Production
Seokjun Kim
 
Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and Rails
Wen-Tien Chang
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
peter_marklund
 
Utiliser Webpack dans une application Symfony
Utiliser Webpack dans une application SymfonyUtiliser Webpack dans une application Symfony
Utiliser Webpack dans une application Symfony
Alain Hippolyte
 
Asp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework CoreAsp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework Core
mohamed elshafey
 
Build Your Own CMS with Apache Sling
Build Your Own CMS with Apache SlingBuild Your Own CMS with Apache Sling
Build Your Own CMS with Apache Sling
Bob Paulin
 
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSDeveloping Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Shekhar Gulati
 
Cooking Perl with Chef: Real World Tutorial with Jitterbug
Cooking Perl with Chef: Real World Tutorial with JitterbugCooking Perl with Chef: Real World Tutorial with Jitterbug
Cooking Perl with Chef: Real World Tutorial with Jitterbug
David Golden
 
Rails Engine Patterns
Rails Engine PatternsRails Engine Patterns
Rails Engine Patterns
Andy Maleh
 
MVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on RailsMVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on Rails
codeinmotion
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
Joshua Long
 
Laravel Restful API and AngularJS
Laravel Restful API and AngularJSLaravel Restful API and AngularJS
Laravel Restful API and AngularJS
Blake Newman
 
Advance java Online Training in Hyderabad
Advance java Online Training in HyderabadAdvance java Online Training in Hyderabad
Advance java Online Training in Hyderabad
Ugs8008
 
Aligning Ember.js with Web Standards
Aligning Ember.js with Web StandardsAligning Ember.js with Web Standards
Aligning Ember.js with Web Standards
Matthew Beale
 
Symfony Live 2018 - Développez votre frontend avec ReactJS et Symfony Webpack...
Symfony Live 2018 - Développez votre frontend avec ReactJS et Symfony Webpack...Symfony Live 2018 - Développez votre frontend avec ReactJS et Symfony Webpack...
Symfony Live 2018 - Développez votre frontend avec ReactJS et Symfony Webpack...
Alain Hippolyte
 
React Native in Production
React Native in ProductionReact Native in Production
React Native in Production
Seokjun Kim
 

Similar to How to dockerize rails application compose and rails tutorial (20)

Rails Applications with Docker
Rails Applications with DockerRails Applications with Docker
Rails Applications with Docker
Laura Frank Tacho
 
Docker For Ruby On Rails : Meaning, Benefits, & Use Cases
Docker For Ruby On Rails : Meaning, Benefits, & Use CasesDocker For Ruby On Rails : Meaning, Benefits, & Use Cases
Docker For Ruby On Rails : Meaning, Benefits, & Use Cases
rorbitssoftware
 
Ruby on Rails and Docker - Why should I care?
Ruby on Rails and Docker - Why should I care?Ruby on Rails and Docker - Why should I care?
Ruby on Rails and Docker - Why should I care?
Adam Hodowany
 
Rails in docker
Rails in dockerRails in docker
Rails in docker
Andrew Klotz
 
Docker as development environment
Docker as development environmentDocker as development environment
Docker as development environment
Bruno de Lima e Silva
 
Ruby microservices with Docker - Sergii Koba
Ruby microservices with Docker -  Sergii KobaRuby microservices with Docker -  Sergii Koba
Ruby microservices with Docker - Sergii Koba
Ruby Meditation
 
Docker composeで開発環境をメンバに配布せよ
Docker composeで開発環境をメンバに配布せよDocker composeで開発環境をメンバに配布せよ
Docker composeで開発環境をメンバに配布せよ
Yusuke Kon
 
Ruby and Docker on Rails
Ruby and Docker on RailsRuby and Docker on Rails
Ruby and Docker on Rails
Muriel Salvan
 
Introducción a contenedores Docker
Introducción a contenedores DockerIntroducción a contenedores Docker
Introducción a contenedores Docker
Software Guru
 
Docker - A Ruby Introduction
Docker - A Ruby IntroductionDocker - A Ruby Introduction
Docker - A Ruby Introduction
Tyler Johnston
 
Intro to Docker for (Rails) Developers
Intro to Docker for (Rails) DevelopersIntro to Docker for (Rails) Developers
Intro to Docker for (Rails) Developers
Chris Johnson
 
Dockerizing Ruby Applications - The Best Practices
Dockerizing Ruby Applications - The Best PracticesDockerizing Ruby Applications - The Best Practices
Dockerizing Ruby Applications - The Best Practices
Kontena, Inc.
 
Docker for the Rubyist
Docker for the RubyistDocker for the Rubyist
Docker for the Rubyist
Brian DeHamer
 
Real World Experience of Running Docker in Development and Production
Real World Experience of Running Docker in Development and ProductionReal World Experience of Running Docker in Development and Production
Real World Experience of Running Docker in Development and Production
Ben Hall
 
Migrating a large code-base to containers by Doug Johnson and Jonathan Lozins...
Migrating a large code-base to containers by Doug Johnson and Jonathan Lozins...Migrating a large code-base to containers by Doug Johnson and Jonathan Lozins...
Migrating a large code-base to containers by Doug Johnson and Jonathan Lozins...
Docker, Inc.
 
Docker for Ruby Developers
Docker for Ruby DevelopersDocker for Ruby Developers
Docker for Ruby Developers
Aptible
 
ContainerDayVietnam2016: Dockerize a small business
ContainerDayVietnam2016: Dockerize a small businessContainerDayVietnam2016: Dockerize a small business
ContainerDayVietnam2016: Dockerize a small business
Docker-Hanoi
 
Introduction to Docker Compose
Introduction to Docker ComposeIntroduction to Docker Compose
Introduction to Docker Compose
Ajeet Singh Raina
 
Troubleshooting Tips from a Docker Support Engineer
Troubleshooting Tips from a Docker Support EngineerTroubleshooting Tips from a Docker Support Engineer
Troubleshooting Tips from a Docker Support Engineer
Jeff Anderson
 
Troubleshooting Tips from a Docker Support Engineer - Jeff Anderson, Docker
Troubleshooting Tips from a Docker Support Engineer - Jeff Anderson, DockerTroubleshooting Tips from a Docker Support Engineer - Jeff Anderson, Docker
Troubleshooting Tips from a Docker Support Engineer - Jeff Anderson, Docker
Docker, Inc.
 
Rails Applications with Docker
Rails Applications with DockerRails Applications with Docker
Rails Applications with Docker
Laura Frank Tacho
 
Docker For Ruby On Rails : Meaning, Benefits, & Use Cases
Docker For Ruby On Rails : Meaning, Benefits, & Use CasesDocker For Ruby On Rails : Meaning, Benefits, & Use Cases
Docker For Ruby On Rails : Meaning, Benefits, & Use Cases
rorbitssoftware
 
Ruby on Rails and Docker - Why should I care?
Ruby on Rails and Docker - Why should I care?Ruby on Rails and Docker - Why should I care?
Ruby on Rails and Docker - Why should I care?
Adam Hodowany
 
Ruby microservices with Docker - Sergii Koba
Ruby microservices with Docker -  Sergii KobaRuby microservices with Docker -  Sergii Koba
Ruby microservices with Docker - Sergii Koba
Ruby Meditation
 
Docker composeで開発環境をメンバに配布せよ
Docker composeで開発環境をメンバに配布せよDocker composeで開発環境をメンバに配布せよ
Docker composeで開発環境をメンバに配布せよ
Yusuke Kon
 
Ruby and Docker on Rails
Ruby and Docker on RailsRuby and Docker on Rails
Ruby and Docker on Rails
Muriel Salvan
 
Introducción a contenedores Docker
Introducción a contenedores DockerIntroducción a contenedores Docker
Introducción a contenedores Docker
Software Guru
 
Docker - A Ruby Introduction
Docker - A Ruby IntroductionDocker - A Ruby Introduction
Docker - A Ruby Introduction
Tyler Johnston
 
Intro to Docker for (Rails) Developers
Intro to Docker for (Rails) DevelopersIntro to Docker for (Rails) Developers
Intro to Docker for (Rails) Developers
Chris Johnson
 
Dockerizing Ruby Applications - The Best Practices
Dockerizing Ruby Applications - The Best PracticesDockerizing Ruby Applications - The Best Practices
Dockerizing Ruby Applications - The Best Practices
Kontena, Inc.
 
Docker for the Rubyist
Docker for the RubyistDocker for the Rubyist
Docker for the Rubyist
Brian DeHamer
 
Real World Experience of Running Docker in Development and Production
Real World Experience of Running Docker in Development and ProductionReal World Experience of Running Docker in Development and Production
Real World Experience of Running Docker in Development and Production
Ben Hall
 
Migrating a large code-base to containers by Doug Johnson and Jonathan Lozins...
Migrating a large code-base to containers by Doug Johnson and Jonathan Lozins...Migrating a large code-base to containers by Doug Johnson and Jonathan Lozins...
Migrating a large code-base to containers by Doug Johnson and Jonathan Lozins...
Docker, Inc.
 
Docker for Ruby Developers
Docker for Ruby DevelopersDocker for Ruby Developers
Docker for Ruby Developers
Aptible
 
ContainerDayVietnam2016: Dockerize a small business
ContainerDayVietnam2016: Dockerize a small businessContainerDayVietnam2016: Dockerize a small business
ContainerDayVietnam2016: Dockerize a small business
Docker-Hanoi
 
Introduction to Docker Compose
Introduction to Docker ComposeIntroduction to Docker Compose
Introduction to Docker Compose
Ajeet Singh Raina
 
Troubleshooting Tips from a Docker Support Engineer
Troubleshooting Tips from a Docker Support EngineerTroubleshooting Tips from a Docker Support Engineer
Troubleshooting Tips from a Docker Support Engineer
Jeff Anderson
 
Troubleshooting Tips from a Docker Support Engineer - Jeff Anderson, Docker
Troubleshooting Tips from a Docker Support Engineer - Jeff Anderson, DockerTroubleshooting Tips from a Docker Support Engineer - Jeff Anderson, Docker
Troubleshooting Tips from a Docker Support Engineer - Jeff Anderson, Docker
Docker, Inc.
 
Ad

More from Katy Slemon (20)

React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdfReact Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
Katy Slemon
 
Data Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdfData Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdf
Katy Slemon
 
How Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdfHow Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdf
Katy Slemon
 
What’s New in Flutter 3.pdf
What’s New in Flutter 3.pdfWhat’s New in Flutter 3.pdf
What’s New in Flutter 3.pdf
Katy Slemon
 
Why Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdfWhy Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdf
Katy Slemon
 
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdfHow Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
Katy Slemon
 
How to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdfHow to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdf
Katy Slemon
 
How to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdfHow to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdf
Katy Slemon
 
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdfSure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Katy Slemon
 
How to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdfHow to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdf
Katy Slemon
 
IoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdfIoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdf
Katy Slemon
 
Understanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdfUnderstanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdf
Katy Slemon
 
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdfThe Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
Katy Slemon
 
New Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdfNew Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdf
Katy Slemon
 
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdfHow to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
Katy Slemon
 
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdfChoose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Katy Slemon
 
Flutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdfFlutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdf
Katy Slemon
 
Angular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdfAngular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdf
Katy Slemon
 
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdfHow to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
Katy Slemon
 
Ruby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdfRuby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdf
Katy Slemon
 
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdfReact Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
Katy Slemon
 
Data Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdfData Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdf
Katy Slemon
 
How Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdfHow Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdf
Katy Slemon
 
What’s New in Flutter 3.pdf
What’s New in Flutter 3.pdfWhat’s New in Flutter 3.pdf
What’s New in Flutter 3.pdf
Katy Slemon
 
Why Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdfWhy Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdf
Katy Slemon
 
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdfHow Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
Katy Slemon
 
How to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdfHow to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdf
Katy Slemon
 
How to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdfHow to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdf
Katy Slemon
 
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdfSure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Katy Slemon
 
How to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdfHow to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdf
Katy Slemon
 
IoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdfIoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdf
Katy Slemon
 
Understanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdfUnderstanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdf
Katy Slemon
 
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdfThe Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
Katy Slemon
 
New Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdfNew Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdf
Katy Slemon
 
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdfHow to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
Katy Slemon
 
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdfChoose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Katy Slemon
 
Flutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdfFlutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdf
Katy Slemon
 
Angular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdfAngular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdf
Katy Slemon
 
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdfHow to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
Katy Slemon
 
Ruby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdfRuby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdf
Katy Slemon
 
Ad

Recently uploaded (20)

Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptxFIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...
Matsushita Laboratory
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data ResilienceFloods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdfEdge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdfHigh Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptxFIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptxFIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptxFIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...
Matsushita Laboratory
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data ResilienceFloods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdfEdge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdfHigh Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptxFIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptxFIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 

How to dockerize rails application compose and rails tutorial

  • 1. HOW TO DOCKERIZE RAILS APPLICATION : COMPOSE AND RAILS TUTORIAL https://www.bacancytechnology.com/
  • 3. 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.
  • 5. Fire the following commands to create a rails app. mkdir ~/projects/noteapp cd ~/projects/noteapp
  • 7. Install Docker Community Edition Install Docker Compose As we are implementing Docker Compose, make sure about the following installations before getting started.
  • 9. 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.
  • 10. FROM ruby:2.3.0 RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs RUN mkdir /noteapp WORKDIR /noteapp ADD Gemfile /noteapp/Gemfile ADD Gemfile.lock /noteapp/Gemfile.lock RUN bundle install ADD . /noteapp // Dockerfile
  • 11. Dockerfile will keep the app code inside an image, building a container with Bundler, Ruby, and other dependencies. Therefore in the root directory of the application, create a new Dockerfile using the command touch Dockerfile and put the content of the above dockerfile inside it. Explanation FROM ruby:2.3.0: Tells Docker to use the prebuilt Ruby image. There are several choices, but this project uses the ruby:2.3.0 image. RUN: To run commands. Here, RUN is for installing different software pieces with Apt. WORKDIR: For stating the base directory from where all the commands are executed. ADD: For copying files from the host machine to our container.
  • 13. Next, open the editor and create a bootstrap Gemfile that loads Rails. source 'https://rubygems.org' gem 'rails', '~>5.0.0' Create an empty Gemfile.lock file to build our Dockerfile. touch Gemfile.lock // gemfile
  • 14. Dockerize Rails App: Add Portability, Modularity, and Scalability to your app Contact Bacancy and hire Rails developer to dockerize your rails application.
  • 16. Finally, moving towards the most important section. The docker-compose.yml file will consist of services needed for your app (web application and DB), for getting each other’s Docker image, and the config for connecting them and making it visible on the port.
  • 17. version: '2' services: db: image: mysql:5.7 restart: always environment: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: noteapp MYSQL_USER: appuser MYSQL_PASSWORD: password // docker-compose.yml
  • 18. ports: - "3307:3306" app: build: . command: bundle exec rails s -p 3000 -b '0.0.0.0' volumes: - ".:/noteapp" ports: - "3001:3000" depends_on - db links: - db
  • 20. Now build the skeleton of the rails application with the help of docker- compose run. docker-compose run app rails new . --force --database=mysql compose– builds the image for the app service, which we have to define inside our docker-compose.yml runs rails new – using that image it runs the app inside a new container database=mysql– to define the database Your application should be created after the command is successfully executed. List the files using ls -l
  • 22. In this section, we will connect the database as rails wants a database to be running on the localhost. We will also alter the database and username for aligning it with the defaults by the MySQL image. When we run the docker-compose command first, it will create a DB container that downloads the MySQL database image and creates a DB based on the environment variables set in the docker-compose.yml file. By now, we have a database container, and app structure created. We need to edit the config/database.yml file and set the configurations from the environment variables. Replace the contents of config/database.yml with the following:
  • 23. version: '2' services: db: image: mysql:5.7 restart: always environment: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: noteapp MYSQL_USER: appuser MYSQL_PASSWORD: password ports: - "3307:3306" app: build: . command: bundle exec rails s -p 3000 -b '0.0.0.0' // docker-compose.yml
  • 24. volumes: - ".:/noteapp" ports: - "3001:3000" depends_on: - db links: - db environment : DB_USER: root DB_NAME: noteapp DB_PASSWORD: password DB_HOST: db After setting up the docker-compose.yml, run the docker-compose build command to build an image for the app and install all the required gems.
  • 25. Run the below command for database creation. docker-compose run --rm app rake db:migrate Before creating any migrations/models, let’s do a docker-compose up to start both app and database services and boot the application after making the changes in database.yml. We can see that rails is running on port 3000 in the container after the command is successfully executed. But, that’s not the port on the host, so we won’t be able to access it on the browser. As per docker- compose, we have exposed the port on the localhost from 3000 to 3001; therefore, it should be available on localhost:3001.
  • 26. Once you are done with the app running on the browser, create a model and perform the migration using these commands in a different console of the project directory. docker-compose run --rm app rails g scaffold note title body:text docker-compose run --rm app rake db:migrate Now, we can access the application on port 3001- localhost:3001/notes and perform actions on the application.
  • 28. mkdir ~/projects/noteapp cd ~/projects/noteapp Create Gemfile and empty Gemfile.lock (content is given above) Create Dockerfile (content is given above) Create docker-compose.yml (content is given above) docker-compose run app rails new . – force –database=mysql Make changes in config/database.yml docker-compose build docker-compose up http://localhost:3001 docker-compose run –rm app rails g scaffold note title body:text docker-compose run –rm app rake db:migrate http://localhost:3001/notes Watch the video tutorial on how to dockerize rails application as well.
  • 29. Source Code: dockerize- rails-app You can also clone the code and go through the project. Here’s the source code of the repository: dockerize-rails-app Commands: Stop, Restart, and Rebuild the Application To stop the application docker-compose down
  • 30. To restart the application docker-compose up To rebuild the application Rebuilding the application is a must when you’re trying different configs and altering the Gemfile or Compose file. ➡Sometimes only docker-compose up – build is enough. ➡But, if you want to rebuild the entire app fully, then use docker-compose run app bundle install, followed by docker-compose up –build for synchronizing changes between the Gemfile.lock and the host.
  • 32. That’s it for the tutorial: how to dockerize rails application using Docker compose. I hope the tutorial was helpful to you for building your own demo app and exploring more. Visit the Ruby on Rails tutorials page for similar tutorials, where you can explore your interests and play around with the code. Looking for skilled rails developers who can help you meet your project requirements? Contact us and hire Rails developer.