I have a Ruby on Rails application that is running is building with docker. I run the docker-compose build
and docker-compose up
commands without issue. It spins up the images and runs puma as expected.
The gems installed are just rails 6.1.5.1
and puma 5.6.4
Here is the output of the docker-compose up
:
my_app | ENVIRONMENT: development
my_app | The Gemfile's dependencies are satisfied
my_app | => Booting Puma
my_app | => Rails 6.1.5.1 application starting in development
my_app | => Run `bin/rails server --help` for more startup options
my_app | Puma starting in single mode...
my_app | * Puma version: 5.6.4 (ruby 3.0.4-p208) ("Birdie's Version")
my_app | * Min threads: 5
my_app | * Max threads: 5
my_app | * Environment: development
my_app | * PID: 9
my_app | * Listening on http://0.0.0.0:3000
my_app | Use Ctrl-C to stop
However, if I run the following command:
docker-compose run --rm my_app rails db:drop db:create db:migrate;
I get the following error:
ENVIRONMENT: development
The Gemfile's dependencies are satisfied
Could not find rails-6.1.5.1 in any of the sources
Run `bundle install` to install missing gems.
If I run:
docker-compose run --rm my_app sh
It drops me to a shell prompt. From this prompt, I type rails --version
it returns the proper version of Rails 6.1.5.1
. If I run, rails db:drop
, I get the following:
Could not find rails-6.1.5.1 in any of the sources
Run `bundle install` to install missing gems.
If I run gem list rails
, it shows a list of rails libraries with the proper version:
rails (6.1.5.1)
sprockets-rails (3.4.2)
Anyone encounter a problem like this?
CodePudding user response:
Can you try this:
- Install the corresponding ruby version on your pc in a native way (without docker)
- Run
bundle install
this will update your Gemfile.lock - Try to build your image again by running
docker-compose build --no-cache