How mohanishkhatri/rails-app-dockerization works
Project Type and Purpose
• This is a full-stack Ruby on Rails web application that has been containerized with Docker.
• It uses MySQL as its persistent datastore, Nginx as a reverse proxy and load balancer, BIND9 for internal DNS resolution, NFS for shared storage, and GitHub Actions for CI/CD and automated backups.
Top-Level Architecture Overview
• VM1 (Ubuntu Server) runs Docker and hosts all application-related containers.
• Rails application containers (three replicas)
• MySQL database container
• Nginx reverse proxy/load-balancer container
• BIND9 DNS container
• VM2 (Ubuntu Server) acts as an NFS server providing:
• Persistent volume for MySQL data
• Shared file storage for uploaded images
• Backup storage
Main Components and Their Interactions
A. Client Tier
• Web browser or API client
• Connects to “myrailsapp.com” over HTTP/HTTPS
B. DNS Layer
• BIND9 container on VM1 resolves “myrailsapp.com” → internal IP of Nginx
C. Load-Balancing & Reverse-Proxy Layer
• Nginx container listens on port 80/443
• Performs SSL termination (self-signed certs)
• Applies rate limiting (limit_req_zone)
• Uses ip_hash for sticky sessions
• Proxies requests to Rails app containers
D. Application Tier
• Three Rails containers (myapp-web-1…3) on a custom Docker network
• Each runs Puma web server, Serves ERB views, Stimulus controllers, ActionCable channels
• Connects to MySQL over network
• Reads/writes uploads to mounted NFS directory
E. Data Tier
• MySQL container with volume “mysql_data” mounted at /var/lib/mysql
• Uses NFS share on VM2 (no_root_squash) for persistence
F. Shared Storage
• NFS server on VM2 exports:
– /storage/mysql_data → MySQL data
– /storage/app_images → Rails uploads (mounted at /app/storage)
G. CI/CD & Backup
• GitHub Actions workflow builds Docker image and pushes to Docker Hub
• VM1 pulls latest image on deploy
• Cron-based backup script runs daily, backs up code and DB dumps to NFS backup-storage
Architectural Patterns and Design Principles
• MVC pattern in Rails (app/models, app/views, app/controllers)
• Micro-services via Docker containers (single-purpose containers)
• Layered architecture (DNS → Proxy → App → DB)
• Infrastructure as code: Dockerfiles, docker-compose.yml, Nginx configs, bind9 exports, UFW rules, fstab
• Persistence decoupled from containers via volumes and NFS
• Fault isolation: multiple Rails app replicas behind load balancer