0% found this document useful (0 votes)
63 views14 pages

Deploying a Rails App with Docker

This document provides a comprehensive guide for deploying a Rails app using Docker, including steps for containerization, setting up Nginx as a reverse proxy and load balancer, and configuring persistent storage with NFS. It outlines the necessary setup for Ubuntu Server, Docker, and PostgreSQL, along with examples of configuration files. The guide also includes instructions for implementing rate limiting and DNS resolution to enhance the deployment process.

Uploaded by

Prateek sbl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views14 pages

Deploying a Rails App with Docker

This document provides a comprehensive guide for deploying a Rails app using Docker, including steps for containerization, setting up Nginx as a reverse proxy and load balancer, and configuring persistent storage with NFS. It outlines the necessary setup for Ubuntu Server, Docker, and PostgreSQL, along with examples of configuration files. The guide also includes instructions for implementing rate limiting and DNS resolution to enhance the deployment process.

Uploaded by

Prateek sbl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

A Step-by-Step Guide to Deploying

a Rails App
• A guide to containerizing a Rails app, setting
up a reverse proxy, load balancing, and using
NFS storage
Setup Overview
• • Deploy VM1 (Ubuntu Server) with Docker
• • Containerize the Rails app & database
• • Configure Nginx as a reverse proxy & load
balancer
• • Enable persistent storage with Docker
Volumes
• • Utilize Docker Compose for deployment
• • Set up DNS resolution
• • Deploy an NFS server for shared storage
Setting Up VM1
• • Install Ubuntu Server
• • Install Docker & Docker Compose
• • Add user to Docker group for permissions

• Example commands:
• ```bash
• sudo apt update && sudo apt install -y
docker.io docker-compose
• sudo usermod -aG docker $USER
Containerizing Rails App
• 1. Create a Dockerfile.
• 2. Define dependencies & environment setup.
• 3. Build the Docker image:
• ```bash
• docker build -t my-rails-app .
• ```
Database Configuration
• • Setup PostgreSQL container
• • Define database connection settings in
`database.yml`

• Example `database.yml`:
• ```yaml
• default: &default
• adapter: postgresql
• host: db
Configuring Nginx Reverse Proxy
• 1. Define the Nginx configuration file
• 2. Use `proxy_pass` to route traffic to Rails app

• Example:
• ```nginx
• server {
• location / {
• proxy_pass http://rails_app;
• }
Load Balancing with Nginx
• 1. Configure multiple Rails app instances
• 2. Set up Nginx as a load balancer

• Example:
• ```nginx
• upstream rails_app {
• server app1:3000;
• server app2:3000;
• }
Persistent Storage with Docker
Volumes
• 1. Create volumes in `docker-compose.yml`
• 2. Assign volumes to database & Nginx for
data persistence

• Example:
• ```yaml
• volumes:
• db_data:
• nginx_config:
Using Docker Compose
• • Define services for Rails app, database, and
Nginx
• • Use a `docker-compose.yml` file to manage
all containers
• • Start services with `docker-compose up`
Implementing Rate Limiting in
Nginx
• • Protect from high traffic & DoS attacks
• • Example:
• ```nginx
• limit_req_zone $binary_remote_addr
zone=mylimit:10m rate=5r/s;
• ```
Configuring DNS Resolution
• • Modify `/etc/hosts` for local resolution
• • Use `dnsmasq` for advanced domain name
resolution

• Example:
• ```bash
• 192.168.1.100 myapp.local
• ```
Configuring NFS Storage
• 1. Install NFS on VM2
• 2. Create shared storage directory
• 3. Export directory and mount on VM1

• Example:
• ```bash
• sudo mkdir -p /storage
• echo '/storage
192.168.1.101(rw,sync,no_root_squash)' |
Final Overview
• • Rails app containerized
• • PostgreSQL database configured with Docker
• • Nginx set up as reverse proxy & load
balancer
• • Persistent storage enabled
• • NFS setup for shared storage
Thank You!
• Questions?

You might also like