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)
Rails app created
Mac OS Catalina Ruby 2.6.5 Rails 6.0.0 MySQL 5.6.47
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.
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