[RAILS] Introduce docker to the application you are creating

Introduction

By first touching docker, I put the Rails application being created in a container and first created a development environment. By the way, I introduced it by referring to this article. [Ruby on Rails I want to introduce Docker to an app I made halfway](https://qiita.com/majorboy/items/9fbfc78fc7bbc1f35e77#5-%E3%82%B3%E3%83% B3% E3% 83% 86% E3% 83% 8A% E3% 82% 92build% E3% 81% 99% E3% 82% 8B-docker-compose-build)

Premise

Rails app created

environment

Mac OS Catalina Ruby 2.6.5 Rails 6.0.0 MySQL 5.6.47

What went

There are two files created this time, "Dockerfile" and "docker-compose.yml". (Since the rails application has already been created as a premise, there is no need to create new "Gemfile" and "Gemfile.lock" this time.) ** However, Gemfile.lock requires bundle install by deleting all the descriptions once before building the container. ** **

Gemfile.lock


#If there is a description, delete it.
#Do the following before building the container
% docker-compose run web bundle install

Then build the container

% docker-compose build 

Then I have to create a DB for docker as well, so execute the following

% docker-compose run web bundle exec rake db:create
% docker-compose run web bundle exec rake db:migrate

This will start the container

% docker-compose up

I was able to start it, but I couldn't connect even though I checked it with a browser. First, check the status of the container.

#Show running Docker container
% docker ps
=>

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
ad25b9c231b9        mysql:5.7           "docker-entrypoint.s…"   7 minutes ago       Up 7 minutes        33060/tcp, 0.0.0.0:4306->3306/tcp   drill_app2_db_1

Only Mysql is working. If you often look at the startup screen,

web_1  | sh: 1: yarn: not found
web_1  | ========================================
web_1  |   Your Yarn packages are out of date!
web_1  |   Please run `yarn install --check-files` to update.
web_1  | ========================================
web_1  | Exiting

The web side? (I don't know how to say it) has not started. The yarn seems to be old, so I will update it.

% docker-compose run web yarn upgrate

=>
Error response from daemon: OCI runtime create failed: container_linux.go:349:
starting container process caused "exec: \"yarn\": executable file not found in $PATH": unknown

This also gives an error and cannot be upgraded. When I was wondering what to do, I found an article in the same situation, so I will change the file settings according to this. Docker-compose up is not possible due to yarn (Your Yarn packages are out of date!)

config/webpacker.yml


# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
#True below=>Change to false

check_yarn_integrity: false

"check_yarn_integrity:" seems to be a setting that will notify you if the package for js is out of date. Here, turn it off once. I checked the check_yarn_integrity option of webpacker

Now start again.

% docker-compose up

This completes the startup for the time being. The browser is also displayed. Connection to mysql is also ok.

At the end

Apparently, webpack was included in rails6 series, so somehow an error of yarn is involved. Then maybe it was bad to delete Gemlock.file. (Sorry, it hasn't been investigated in detail yet.)

Recommended Posts

Introduce docker to the application you are creating
Rails6 I tried to introduce Docker to an existing application
You are required to use winpty with docker exec [Windows]
Try to introduce OpenCV to Android application
Until you introduce fonts to Rails
[GCP] Until you push the local Docker image to the Container Registry
Procedure for migrating Rails application development environment to Docker even if you are inexperienced (Rails5 + MySQL8.0 + docker-compose)
Investigate the replacement from Docker to Podman.
The road to creating a music game 2
The road to creating a music game 3
The road to creating a music game 1
[Java] Are you reading the error message properly? [How to read the stack trace]
If you are using Android Room and want to change the column definition
Introduce Docker to the development environment and test environment of existing Rails and MySQL applications
About the case where "Docker" freeter tried to put Docker in the existing Rails application
How to check the logs in the Docker container
When you want to use the method outside
How to delete the database when recreating the application
[Java / PostgreSQL] Connect the WEB application to the database
Push the image to docker hub using Jib
Introduce dotenv to Docker + Rails to manage environment variables
The road to creating a Web service (Part 1)
How to install Docker in the local environment of an existing Rails application [Rails 6 / MySQL 8]
I tried to summarize the state transition of docker
If you want to recreate the instance in cloud9
Check the rate limit application status of docker pull
Are you using the default method of the interface properly?
Completely delete the migration file that you failed to delete
Command to try using Docker for the time being
If you want to make a Java application a Docker image, it is convenient to use jib.
What to do if you change the Listen Address from the settings screen with Mattermost docker
Memo that transitions to the login screen if you are not logged in with devise
When you want to reflect the Master Branch information in the Current Branch you are currently working on