Since an error occurred when building the environment with docker and adding gems I will share information as a memorandum!
docker rails (5.2.0) ruby (2.7.1) mysql (5.7) nginx puma
When I added the devise gem in the Gemfile and ** docker-compose run --rm rails bundle install **, the following error occurred
~ RailsApp % docker-compose run --rm rails bundle install
Starting railsapp_db_1 ... done
Fetching gem metadata from https://rubygems.org/.............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies....
Bundler could not find compatible versions for gem "railties":
In snapshot (Gemfile.lock):
railties (= 5.2.4.3)
In Gemfile:
devise (= 4.1.0) was resolved to 4.1.0, which depends on
railties (< 5.1, >= 4.1.0)
rails (~> 5.2.2) was resolved to 5.2.4.3, which depends on
railties (= 5.2.4.3)
Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.
I didn't know what was the cause, but for the time being, it said, "** bundle update ** may solve it." ** run docker-compose run --rm rails bundle update **
↓↓↓↓↓↓↓↓
~ RailsApp % docker-compose run --rm rails bundle update
Starting railsapp_db_1 ... done
Fetching gem metadata from https://rubygems.org/.............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...........................
Bundler could not find compatible versions for gem "railties":
In snapshot (Gemfile.lock):
railties (= 5.2.4.3)
In Gemfile:
devise (= 4.1.0) was resolved to 4.1.0, which depends on
railties (< 5.1, >= 4.1.0)
rails (~> 5.2.2) was resolved to 5.2.4.3, which depends on
railties (= 5.2.4.3)
It didn't work ...
From the conclusion, it seems that the cause of the error was that the gem ** devise was not in the list. ** **
I referred to the following article.
https://qiita.com/hatorijobs/items/2928e152f22d009b07d0
If you execute this article as it is, it will be solved, but if you are working with docker, there are some commands It's different, so I'll explain it here.
Operate in the following order.
1. docker-compose exec [Arbitrary service name]Check the gem list with the gem list and make sure there are no devise gems.
2. docker-compose exec [Arbitrary service name]Install devise with gem install devise.
3.Docker again-compose exec [Any service name]Check the gem list with gem list and devise(4.7.2)Make sure there is.
4.In Gemfile**gem 'devise','4.7.2'Describe
5. docker-compose run --Run rm rails bundle update
Let's look at them in order. ↓↓↓↓↓↓↓↓
** 1. Check the list of gems with docker-compose exec [arbitrary service name] gem list, and make sure that there is no devise gem. ** **
~ RailsApp % docker-compose exec app gem list
*** LOCAL GEMS ***
actioncable (5.2.4.3, 5.2.2)
actionmailer (5.2.4.3, 5.2.2)
actionpack (5.2.4.3, 5.2.2)
actionview (5.2.4.3, 5.2.2)
actionjob (5.2.4.3, 5.2.2)
~abridgement~
web-console (3.7.0)
** 2. Install devise with docker-compose exec [arbitrary service name] gem install devise. ** **
~ RailsApp % docker-compose exec app gem install devise
Fetching warden-1.2.8.gem
Fetching bcrypt-3.1.13.gem
~abridgement~
Successfully installed devise-4.7.2
5 gems installed
** 3. Check the list of gems with docker-compose exec [arbitrary service name] gem list again, and confirm that devise (4.7.2) exists. ** **
~ RailsApp % docker-compose exec app gem list
*** LOCAL GEMS ***
actioncable (5.2.4.3, 5.2.2)
actionmailer (5.2.4.3, 5.2.2)
actionpack (5.2.4.3, 5.2.2)
actionview (5.2.4.3, 5.2.2)
actionjob (5.2.4.3, 5.2.2)
~abridgement~
devise (4.7.2)
~abridgement~
web-console (3.7.0)
** 4. Write gem'devise', '4.7.2' in Gemfile **
Gemfile.
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.2.1'
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.3.18', '< 0.5'
# Use Puma as the app server
~abridgement~
#Addition of login function
gem 'devise','4.7.2'
~abridgement~
** 5. Run docker-compose run --rm rails bundle update **
~ RailsApp % docker-compose run --rm rails bundle update
If there is no error with this, we win
I've noticed some things when dealing with errors, so I'll share them.
docker-Running compose exec app gem install devise will install the latest version of gem.
We have decided that there is no problem with the latest version, so we have omitted the explanation of how to specify the version.
* If you know how to do it, please let me know!
By the way, I found a site where all version history of devise is posted, so I will link the URL. https://rubygems.org/gems/devise/versions
[Any service name]What is docker-compose.This is the service name specified in yml.
It can be decided arbitrarily, but it seems that there are many people who set it on the web such as db or app on any site.
Regarding Rails and docker, I will continue to post articles about errors regularly for output. Also, I think there were some points that I couldn't reach in my first post, but thank you for reading to the end! !! !!
that's all
Recommended Posts