[RUBY] Rails6 I tried to introduce Docker to an existing application

Purpose of this article Docker was able to manage to introduce it while wearing down his spirit, frightened every day by the anxiety that he would lose his place at home if he did not succeed in changing jobs. A memorandum to make the hardship only once w

Procedure
  1. Change DB from Splite3 to Postgresql
  2. Add file
  3. Edit Dockerfile, docker-compose.yml, database.yml, webpacker.yml
  4. Download Docker for mac
  5. Type command

Change DB from Splite3 to Postgresql It seems that it has become possible to change it with a command from Rails 6.
$ rails db:system:change --to=postgresql

Add and edit files In the root directory of the app, Dockerfile docker-compose.yml Add and edit the above two.
#Dockerfile

FROM ruby:2.7.1 #Match the version. Check with Gemfile
RUN curl https://deb.nodesource.com/setup_12.x | bash
RUN curl https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list

RUN apt-get update && apt-get install -y nodejs yarn postgresql-client
RUN apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y postgresql-client --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs

WORKDIR /myapp

ADD Gemfile /myapp/Gemfile
ADD Gemfile.lock /myapp/Gemfile.lock

RUN gem install bundler
RUN bundle install

ADD . /myapp

↑ I got various errors and I went with this, but I still get a warning. Pien

#docker-compose.yml

version: '3'
services:
  db:
    image: postgres
    ports:
      - '5432:5432'
    volumes:
      - postgresql-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_PASSWORD=password # If you do not set an arbitrary password, an error will occur.
  web:
    build:
      context: .
      dockerfile: Dockerfile
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    tty: true
    stdin_open: true
    depends_on:
      - db
    ports:
      - "3000:3000"
    volumes:
      - .:/myapp #Source code changes are immediately reflected in Docker
volumes:
  postgresql-data:
    driver: local

database.yml



#Comment out omitted
#password is docker-compose.What was set in yml

default: &default
  adapter: postgresql
  encoding: utf8
  host: db
  username: postgres
  password: password 
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: mayby_docker_development

#Comment out omitted

test:
  <<: *default
  database: mayby_docker_test

#Comment out omitted

production:
  <<: *default
  database: mayby_docker_production
  username: mayby_docker
  password: <%= ENV['MAYBY_DOCKER_DATABASE_PASSWORD'] %>

webpacker.yml


check_yarn_integrity: false
#default,It seemed to be useless unless both development were set to false.

Download Docker for mac I will download it from the official website. https://docs.docker.jp/docker-for-mac/install.html

Type a command Since it is long, it will wither when an error occurs.
$ docker-compose build

Create a DB and migrate.

$ docker-compose run web rake db:create db:migrate

If it is displayed at local: 3000, it seems that it was done for the time being.

$ docker-compose up

I've finally come this far, but it doesn't appear! The browser says that it was simply rejected by the local host, so please refer to this

[Rails] What to do if "Cannot render console from !" Appears in the rails s log

config/environment/development.rb



 config.web_console.whitelisted_ips = 'Rejected IP address'

I did, but there are still others

There was something called a segmentation fault related to SaaS. When I try to google with the last power,

Resolved an issue with Rails 6 segfaulting

There was a god-like blog.

assets.rb


#Stop parallel compilation of asetts (countermeasures against segmentation errors)
Rails.application.config.assets.configure do |env|
  env.export_concurrent = false
end

It is said that a countermeasure gem will be released, but I am not sure yet, so I will wait for a while.

Last It's a trendy Docker, It's not a real thing, so you can't understand it unless you actually experience it. Next, I will try deploying to AWS.

Recommended Posts

Rails6 I tried to introduce Docker to an existing application
I tried to introduce CircleCI 2.0 to Rails app
I tried to develop an application in 2 languages
I tried to build an environment using Docker (beginner)
About the case where "Docker" freeter tried to put Docker in the existing Rails application
I tried to make an introduction to PHP + MySQL with Docker
How to install Docker in the local environment of an existing Rails application [Rails 6 / MySQL 8]
Introduce two-factor authentication to your Rails application
Migrate existing Rails 6 apps to Docker environment
Introduced Vue.js to an existing Rails app
I tried to build a simple application using Dockder + Rails Scaffold
I tried to make an Android application with MVC now (Java)
Rails Tutorial Extension: I tried to create an RSS feed function
What is Docker? I tried to summarize
Introduced Vuetify to an existing Rails app
After learning Progate, I tried to make an SNS application using Rails in the local environment
I tried to summarize the stumbling points when developing an Android application
I tried to make an automatic backup with pleasanter + PostgreSQL + SSL + docker
I tried to verify AdoptOpenJDK 11 (11.0.2) with Docker image
Downgrade an existing app created with rails 5.2.4 to 5.1.6
[Rails] I tried to raise the Rails version from 5.0 to 5.2
I tried to organize the session in Rails
I tried installing docker on an EC2 instance
Introduce docker to the application you are creating
[Rails] How to build an environment with Docker
Introduce dotenv to Docker + Rails to manage environment variables
[Rails] Create an application
I tried to make a machine learning application with Dash (+ Docker) part3 ~ Practice ~
[First environment construction] I tried to create a Rails 6 + MySQL 8.0 + Docker environment on Windows 10.
I tried to summarize the state transition of docker
I introduced Docker to Rails 6, so I summarized it (beginner)
[Swift] Trajectory until adding WidgetKit to an existing application
[Rails] How to connect to an external API using HTTP Client (I tried connecting to Qiita API)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (6)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (3)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (2)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (1)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (4)
How to create an application
[Rails 6] Dockerize existing Rails apps [Docker]
I tried Rails beginner [Chapter 1]
I tried the Docker tutorial!
I tried Rails beginner [Chapter 2]
I tried BIND with Docker
I tried to verify yum-cron
I tried to modernize a Java EE application with OpenShift.
[Rails] I tried to create a mini app with FullCalendar
I want to push an app made with Rails 6 to GitHub
What to do when you launch an application with rails
I tried to introduce UI animation to Pokedex using Poké API
Introduced Vue.js to an existing Rails app
I tried using Hotwire to make Rails 6.1 scaffold a SPA
I tried to create React.js × TypeScript × Material-UI on docker environment
I tried to build the environment little by little using docker
[Rails] I tried to implement batch processing with Rake task
I tried to build the environment of WSL2 + Docker + VSCode
I tried to implement a buggy web application in Kotlin
[Rails] I tried to implement "Like function" using rails and js
I tried to create a padrino development environment with Docker
[Rails 6.0, Docker] I tried to summarize the Docker environment construction and commands necessary to create a portfolio
I tried to build an API server with Go (Echo) x MySQL x Docker x Clean Architecture