[RUBY] Procedure for building a Rails application development environment with Docker [Rails, MySQL, Docker]

Hello. This time, I summarized the procedure to build a Rails application development environment with Docker. I haven't studied enough yet, so I would appreciate it if you could point out any corrections or improvements.

Advance preparation

-Install Docker-for-mac

environment

Ruby: 2.5.8 Rails: 5.2.4.3 MySQL: 5.7.31 Docker: 19.03.8 Docker Compose: 1.25.4

procedure

1. Create the root directory of the project

terminal



$ mkdir test-app

First, create the root directory of your project.

2. Add files directly under the root directory

terminal



$ cd test-app
$ touch Dockerfile docker-compose.yml Gemfile Gemfile.lock

Create four files, Dockerfile, docker-compose.yml, Gemfile, and Gemfile.lock, directly under the created root directory. The contents of each file are as follows. (Leave Gemfile.lock empty.)

Dockerfile



FROM ruby:2.5
RUN apt-get update && apt-get install -y \
    build-essential \
    nodejs
WORKDIR /test-app
COPY Gemfile Gemfile.lock /test-app/
RUN bundle install

docker-compose.yml



version: '3'

volumes:
  mysql-data:

services:
  web:
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    ports:
      - '3000:3000'
    volumes:
      - '.:/test-app'
    tty: true
    stdin_open: true
    depends_on:
      - db
    links:
      - db

  db:
    image: mysql:5.7
    volumes:
      - 'mysql-data:/var/lib/mysql'
    environment:
      - 'MYSQL_ROOT_PASSWORD=test-app'

Gemfile



source 'https://rubygems.org'
gem 'rails', '~>5.2'

3. Set up Rails in the container

terminal


$ docker-compose run --rm web rails new . --force --database=mysql --skip-bundle --skip-test

Run rails new inside a web container. I was planning to use RSpec for testing this time, so I've also added --skip-test.

4. Edit the created config / database.yml

Edit the config / database.yml created by Rails setup as follows.

config/database.yml



default: &default
  adapter: mysql2
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password: test-app   #docker-compose.yml MYSQL_ROOT_Set the value of PASSWORD
  host: db   #docker-compose.Match with yml service name

development:
  <<: *default
  database: test-app_development

5. Start the container

terminal



$ docker-compose up --build -d
$ docker-compose run --rm web rails db:create

Now, when you visit http: // localhost: 3000, you should see the Rails home screen.

rails_home_pic.png

reference

-Too polite Docker-compose rails5 + MySQL on Docker environment construction (Docker for Mac) -[Rails] Procedure for creating Rails + MySQL development environment with Docker -Docker x Ruby on Rails x MySQL environment construction --Dockerfile Best Practices

Recommended Posts

Procedure for building a Rails application development environment with Docker [Rails, MySQL, Docker]
Rails application development environment construction with Docker [Docker, Rails, Puma, Nginx, MySQL]
Build a development environment for Django + MySQL + nginx with Docker Compose
"Rails 6 x MySQL 8" Docker environment construction procedure for sharing with teams
Build a development environment for Docker + Rails6 + Postgresql
Creating a java web application development environment with docker for mac part1
Build a local development environment for Rails tutorials with Docker (Rails 6 + PostgreSQL + Webpack)
Create a java web application development environment with docker for mac part2
Procedure for migrating Rails application development environment to Docker even if you are inexperienced (Rails5 + MySQL8.0 + docker-compose)
Rails + MySQL environment construction with Docker
[Environment construction with Docker] Rails 6 & MySQL 8
Procedure for introducing Docker into the development environment of existing Rails applications [Rails, MySQL, Docker]
I made a development environment with rails6 + docker + postgreSQL + Materialize.
Build a web application development environment that uses Java, MySQL, and Redis with Docker CE for Windows
Building Rails 6 and PostgreSQL environment with Docker
Build a PureScript development environment with Docker
Create a MySQL environment with Docker from 0-> 1
[Docker] Development environment construction Rails6 / Ruby2.7 / MySQL8
Build a Wordpress development environment with Docker
How to install Pry after building Rails development environment with Docker
[Rails] Development with MySQL
Build a WordPress development environment quickly with Docker
Rails6 [API mode] + MySQL5.7 environment construction with Docker
Build a development environment for Docker, java, vscode
Wordpress local environment construction & development procedure with Docker
Create a Spring Boot development environment with docker
Build debug environment on container --Build local development environment for Rails tutorial with Docker-
I built a rails environment with docker and mysql, but I got stuck
I tried to build a Firebase application development environment with Docker in 2020
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
Template: Build a Ruby / Rails development environment with a Docker container (Ubuntu version)
Template: Build a Ruby / Rails development environment with a Docker container (Mac version)
Complete roadmap for building environment up to Docker + rails6 + MySQL + bootstrap, jquery
Building an environment for WordPress, MySQL and phpMyAdmin with Docker Compose on EC2
Stable development environment construction manual for "Rails6" with "Docker-compose"
[Docker] Rails 5.2 environment construction with docker
A memorandum when building an environment with Ruby3.0 x Rails6.1 x Docker x CentOS Stream
Build Rails (API) x MySQL x Nuxt.js environment with Docker
A memo when building a Rails 5.2 development environment using Docker Desktop + WSL2 on Windows 10 Home
Build a local development environment for Open Distro for Elasticsearch with multiple nodes using Docker
How to quit Docker for Mac and build a Docker development environment with Ubuntu + Vagrant
[For beginners] Until building a Web application development environment using Java on Mac OS
Docker × Java Building a development environment that is too simple
[Procedure 1 for beginners] Ruby on Rails: Construction of development environment
How to build Rails, Postgres, ElasticSearch development environment with Docker
I tried to create a padrino development environment with Docker
Building an environment for creating apps with Rails and Vue
Measures for permissions when building MySQL with Docker on WSL2
Create a Vue3 environment with Docker!
Deploy a Docker application with Greengrass
Build a Node.js environment with Docker
Environment construction for Servlet application development
Environment construction with Docker for beginners
Build environment with vue.js + rails + docker
Build Rails environment with Docker Compose
Rails on Docker environment construction procedure
Build a local development environment for Rails tutorials with Docker-Introduce Bootstrap and Font Awesome with Webpack-
Build a SPA for Laravel 6.2 / Vue.js / Nginx / Mysql / Redis with Docker
Ruby on Rails development environment construction with Docker + VSCode (Remote Container)
(For myself) Try creating a C # environment with docker + code-server, cloud9