How to create Ruby on Rails 7 and Mysql project with Docker

Sometimes I have to work on multiple pc. It's helpful if project is configured on docker. I was searching a good docker-composer.yml template on github. But most of the case for rails 7 it was not working perfect. Sometimes I am getting a good template which was working perfect for rails 7, but it was configured for Postgreesql. But I need mysql. Sometimes I am getting template which was works perfectly for the old version of rails, not working for the new version.



So I have configured docker with Rails 7 and Mysql. If anyone want to create a fresh new project it will be helpful. Here is the git repo -

https://github.com/Mashpy/rails-7-docker-template-with-mysql

1. First clone the project

$ git clone https://github.com/Mashpy/rails-7-docker-template-with-mysql.git

2. Rename the project name as your wish

$ mv rails-7-docker-template-with-mysql your_project_name

3. Change directory -

$ cd your_project_name

4. Update your rails version on the Gemfile -

source 'https://rubygems.org' gem 'rails', '7.0.3'

5. Update Ruby version on Dockerfile -

FROM ruby:3.1.2-slim

6. Now install new rails app -

$ docker-compose run app rails new . --force --database=mysql --skip-bundle

7. Build the docker image -

$ docker-compose build

8. Update database details on config/database.yml file.

default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: "root"
host: mysql

development:
<<: *default
database: dev

test:
anc

9. Run -

$ docker-compose up

10. Browse http://localhost:3000 


If it's work perfectly please make star on my repo. If you have any question you can ask me.

Comments

Popular Posts

Install and configure Network simulator (ns3) on Ubuntu 14.04